• 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

Is it possible to delay without using Thread.sleep()

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is because I suspect my application has a multi threading issue because of this statement(2 programs running at the same time)

This is my code:

However, it does not go to the exception at all, let's say I run an application in task scheduler, then stop in task scheduler, but sometimes the process doesn't seem to stop completely, then run again.
Will there be 2 threads? Already specified do not start a new instance in task scheduler, in that case is it a multi threading issue?

 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you kick off a different process there are two different processes.
Its not really clear from the info that you provided what you are trying to do ... maybe more details might help
 
cle tan
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to know
for just delay purpose in my application
should I use thread.sleep()?

http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program.aspx

Will it cause any multi threading issues?
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

cle tan wrote:I would like to know
for just delay purpose in my application
should I use thread.sleep()?

http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program.aspx

Will it cause any multi threading issues?





for just delay purpose in my application
should I use thread.sleep()?



The question is why do you need a delay in the application? In most (well almost all) cases thread-sleep-is-a-sign-of-a-poorly-designed-program

Will it cause any multi threading issues?


Yes. unless you are 100% sure what you are doing. Anything that's multi-threaded needs careful code consideration
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd use Thread.sleep if there are, say 4 threads, and assume threads 1,2,3 hog the limelight for some reason. Suppose I want to give a chance for other thread 4 to run, I would use
Thread.sleep on Thread 1,2 3 so that output from Thread 4 is visible too.
 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but then Thread.sleep() will also take lock along with it when goes to sleep.

yeah then thread 4 can do some work on un-blocked methods but can't do in critical blocked method by rest of the thread 1/2/3.

so it won't solve purpose completely....
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sunderam Goplalan wrote:I'd use Thread.sleep if there are, say 4 threads, and assume threads 1,2,3 hog the limelight for some reason. Suppose I want to give a chance for other thread 4 to run, I would use
Thread.sleep on Thread 1,2 3 so that output from Thread 4 is visible too.



You don't need to do that. Unless you have a very old or very unusual JVM implementation or underlying OS and hardware, those three will handle scheduling pretty well without any interference from you.

If you have measured and observed that some threads are being starved, you could try adjusting the various threads' relative priorities. As an absolute last resort, you might try calling Thread.yield(). Although, really, you shouldn't need to concern yourself with thread scheduling.
 
reply
    Bookmark Topic Watch Topic
  • New Topic