• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pause and Resume any Thread  RSS feed

 
Ram Chhabra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you please tell me that how to pause and resume any Thread in application?

In my condition i cannot use wait() and notify() as i cant use synchronization.

Thanks
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Chhabra wrote:In my condition i cannot use wait() and notify() as i cant use synchronization.


Any reason for such a stand.
 
Ram Chhabra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making web application and i don't want to make any of the methods synchronized, that's why.
 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread can go into runnable state by using the static method Thread.sleep(duration).

This will pause the current thread to stop executing for that duration.

Else if you want your thread to execute after some thread has finished then you can use the join() method of the thread class.

These methods need not be called from the synchronised context.

~Aditya
 
Ram Chhabra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Again my problem arises, i can't use synchronization
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like the previous poster said, you can use Thread.sleep() without using synchronization.



You would call it like:


Saying you 'can't' use synchronization and 'don't want to' are two different thinks. You will be wasting CPU cycles by avoiding synchronization. It seems like a total waste to avoid one of the most useful tools for multi-threaded application. Is it really a requirement (where does it come from)?
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Small typo there. It should be,

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!