• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread stop  RSS feed

 
Jos� M. Crist�bal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
I'm developing an application using JMX. Every managed object extends an abstract class that includes a method called start(). That method has to be called in order to start the managed object. I want to invoke that method using threads but that invocation could stop the thread for a long time.
I have included a timeout for that method execution, but the only way to properly kill that threat is using the Thread.stop() method. I know that the stop method is deprecated, but the rest methods provided are not suitable for this situation.
I have read almost the rest of the Threads and Synchonization forum looking for topics with situations like that but i couldn't find them.
thanks a lof for reading. Any help will be appreciated!!!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you don't have access to the 'run ()' - methods of these threads?
Then you simply write:
 
Jos� M. Crist�bal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer.
The run() method of that thread contains an invocation to an object's method called start(). That object is not a Thread, so the start() is not the Thread's start() method.
I don't know the operations included into that start() method and the invocation is going to be executed using the MBeanServer (that's part of JMX). For example, if the start() method contains an infinite loop the Thread remains running infinitely. This is the kind of situation I'm trying to avoid.
I hope I've been clear enough.
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to interrupt the method?
 
Jos� M. Crist�bal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course I Tried!!!

In fact, the interrupt method works if the inner Thread remains slept for a long time, for example, if I sleep a Thread into an infinite loop like this

while (true){
Thread.getCurrentThread().sleep(x milis);

}

The result of interrupting the thread is the finalization of the while loop and the processing of the following lines of code. But that's not the situation I'm trying to solve. I want to make the execution stop finally without processing more instructions.

Anyway, thanks for your replies.

PD. Excuse the written code. I'm not sure this particular method exists in that way..... sorry....
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well in the example u gave, u can try to check Thread.currentThread().isInterrupted() and skip the rest of the run method.

But since you dont control the content of the start() in the monitored object.....

This is interesting q. please let us know if you find the answare.
 
kay lin
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don't you try to post some snippets of the code here,
then it'd be easier for us to understand, hence, we'd be able to help you better?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!