FranklinRaj22
asked on
spawning thread in a prgram to call a seperate class
I would like to spawn a thread based upon a condition in my main program, the new thread should run in the back ground doing its work and the main program should countinue running in the foreground in a seperate thread.
I would use a SwingWorker. We need more detail though
If you got 2 worker jobs I would spawn 2 Threads:
public class Work1 extends Thread
{
....................
}
public class Work2 extends Thread
{
....................
// Main class:
Thread one = new Work1().start();
Thread one = new Work2().start();
.......................... .
Be careful to always spawn threads if activated by a button,
as you must not 'stay' working in the event thread (actionPerformed() ).
;JOOP!
public class Work1 extends Thread
{
....................
}
public class Work2 extends Thread
{
....................
// Main class:
Thread one = new Work1().start();
Thread one = new Work2().start();
..........................
Be careful to always spawn threads if activated by a button,
as you must not 'stay' working in the event thread (actionPerformed() ).
;JOOP!
ASKER
sage,
thanks but i will tel ya my situation, see the pseudocode below , here the main class should countinue its wrk in a seperate thread after it spawns a thread to do the Work1 class.
public class Work1 extends Thread
{
....................
}
//main class
......
new Work1().start();(this would run in the back ground through the entire life time of the application)
.....
.....
thanks but i will tel ya my situation, see the pseudocode below , here the main class should countinue its wrk in a seperate thread after it spawns a thread to do the Work1 class.
public class Work1 extends Thread
{
....................
}
//main class
......
new Work1().start();(this would run in the back ground through the entire life time of the application)
.....
.....
Is there a GUI involved?
ASKER
yes , the main program which i mentioned would be a SWING GUI, whereas this newly spawned thread would be updating a few file , which my main program might use in alater poitn of time.
Then definitely use a SwingWorker. Do your file manipulation in the doInBackground method
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.