multithreading - SwingWorker threads in Java -
i'm working swing @ minute , i've run bit of problem, realize it's not possible execute swingworker thread more once http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html.
my question is possible create new instance of same swingworker thread? in code here i've called worker thread 'worker'
swingworker<void, void> worker = new swingworker<void, void>(){ public void doinbackground(){ } };
is possible create more 1 instance of thread can call more once? i've tried like
(new swingworker<void, void> worker).execute();
but doesn't seem work. appreicated!
what problem creating new swingworker every time need it?
if need store state in instance needs run many times can use runnable or callable interfaces , give swingworker execution. have create swingworker every time, runnable or callable instance can same.
in example below worker instance created every time runnable instances same.
class foo { private final runnable executeinbackground; private final runnable executeindone; public foo(runnable done, runnable background) { executeindone = done; executeinbackground = background; } public void execute() { swingworker<void, void> worker = new swingworker<void, void>() { public void doinbackground() { executeinbackground.run(); } public void done() { executeindone.run(); } }; worker.execute(); } }
Comments
Post a Comment