File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Thread stop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread stop" Watch "Thread stop" New topic
Author

Thread stop

Jos� M. Crist�bal
Greenhorn

Joined: May 04, 2004
Posts: 4
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

Joined: Jun 02, 2003
Posts: 1923

you don't have access to the 'run ()' - methods of these threads?
Then you simply write:


http://home.arcor.de/hirnstrom/bewerbung
Jos� M. Crist�bal
Greenhorn

Joined: May 04, 2004
Posts: 4
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

Joined: Jan 09, 2001
Posts: 147
Did you try to interrupt the method?
Jos� M. Crist�bal
Greenhorn

Joined: May 04, 2004
Posts: 4
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

Joined: Jan 09, 2001
Posts: 147
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

Joined: May 20, 2004
Posts: 132
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?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Thread stop
 
Similar Threads
Ambiguous question on thread?
Calling methods before start()
Thread has finished but Threads Global Vars are still accesible
directly stopping a thread
run()