• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to make a Thread run for particular amount of Time

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I want to start a Thread , that actually runs for one minute and stops after it .


Please let me know how to achive this . Thanks .
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can join on a thread for some time and after the join if it still is alive, interrupt to kill it.

Your thread must be able to handle the interruption that is going to occur.
This is one of the possible ways... may be someone else will come up with some more possibilities
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can join on a thread for some time



Thanks for your reply , But do this operation , there should be two threads .

Right now , a normal java class is calling this Thread.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran V wrote:But do this operation , there should be two threads .


Right now , a normal java class is calling this Thread.


Non-sequitur?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Non-sequitur?



what do you mean by above ??
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Non_sequitur_(logic)
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be honest, I come to the same conclusion.

The current thread starts this new thread. It should not block afterwards. However, this new thread needs to be limited in time. Using join on this thread from the current thread will block the current thread. To prevent that, the current thread starts two threads:
- the timed thread
- a thread that will call join on the timed thread
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:To be honest, I come to the same conclusion.

The current thread starts this new thread. It should not block afterwards. However, this new thread needs to be limited in time. Using join on this thread from the current thread will block the current thread. To prevent that, the current thread starts two threads:
- the timed thread
- a thread that will call join on the timed thread


2 threads - thats really nice! Good one,Rob!
 
rubbery bacon. rubbery tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic