• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute long time process in java  RSS feed

 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i have situation to execute long time process i like to show the status immediatly i mean i though of create asynchronous call

so for that i plan to create java thread when the process start.

my doubt is when the process completed how can i check thread still run the process or how to know the status moreover i need to stop the thread on the end of process completed.

please let me knowhow to know the status and stop the thread
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use isAlvie() method of Thread class to check if the thread is running or died.
To stop the thread from the other (main) thread you can call interrupt method on this thread.
In the thread (in its run method) you must periodically use isInterrupted or interrupted methods to check if thread has been requested to stop,
and if yes - return from it's run method.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are waiting for a thread to finish, you can simply call the thread's join() method. That will block until the thread is finished. There's a version with a timeout if you need it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!