• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread-Killing.

 
Piyush Mattoo
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a Java application which involves multithreading.Our application gets locked up and wouldn't stop when used as a windows service. The two threads in background continue to run even when we try to close the application. I was wondering how can i kill the two background threads. Any inputs will be appreciated. I can provide further details if needed.
In our application, in the main class two threads are created using Timer and are scheduled for execution after regular intervals of time. There is an Exit-handler class as well which cleans up the directory contents and in the exit-handler, the two threads(FTP and Upload) are not killed. So, typically we might need to implement some method which will kill these threads when they invoke the exit handler.We might need to use the cancel() to terminate the timer's task thread.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the problem threads set to be daemon? If you're not sure, review the Thread JavaDoc. If they're blocking on something like non-interruptible IO it may be hard to get their attention.
 
Piyush Mattoo
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not using the timer(boolean) constructor to create the constructor.So, i believe the threads are not daemons.If i make them as daemons by passing true to the timer constructor, the application stops after a while and didn�t run after that. That could be because the threads are scheduled for execution after regular intervals separated by specific period as we are using scheduleAtFixedRate(TimerTask task, long delay,long period) method to schedule the tasks.
 
Piyush Mattoo
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't realize that.Have made the change.

Cheers!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!