S
Stefan Ram
I am new to multithreading in Java. In a thread's code, I write:
void run()
{ if( irq() )cleanup(); else
{ firstStep();
if( irq() )cleanup1(); else
{ secondStep();
...
The user can request the thread to end using a GUI button.
The thread has to check often whether the user has requested
this, and then has to stop.
Now, all the thread's code is messed up with polling the
status of the user request, before each and every other action.
Writing and maintaining the code is more difficult. I cannot
simply write
void run()
{ firstStep();
secondStep();
...
cleanup(); }
but have to write the code as above.
Is this the usual way to proceed? Or can I simplifiy this somehow?
void run()
{ if( irq() )cleanup(); else
{ firstStep();
if( irq() )cleanup1(); else
{ secondStep();
...
The user can request the thread to end using a GUI button.
The thread has to check often whether the user has requested
this, and then has to stop.
Now, all the thread's code is messed up with polling the
status of the user request, before each and every other action.
Writing and maintaining the code is more difficult. I cannot
simply write
void run()
{ firstStep();
secondStep();
...
cleanup(); }
but have to write the code as above.
Is this the usual way to proceed? Or can I simplifiy this somehow?