• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread stop

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic