• Post Reply Bookmark Topic Watch Topic
  • New Topic

about pausing of execution  RSS feed

 
kalyan at tcs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

is there any way to pause execution of a part of java program for a particular time without using Thread.sleep() method


thanks,


bye
kalyan
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Well, there is Thread.suspend, but it's deprecated. Anyway, why would
you like to do that? (I mean, your question is quite vague. Tell us more
and we might be able to help.)

Petr
 
kalyan at tcs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

in my program , iam having 2 methods which display screens on screen ,
and iam calling them sequentially , hence iam not able to see the output of first method .so i want to pause execution of my program for some time at end of first method and before the second , so that i can view outputs of both

i was restricted not to use Thread concept , pls help me , is there is any other way to over come this


bye
kalyan
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could put in code that waits for some user input before proceeding, a bit like C's getch()

For example,



displays 'Hello', and then waits for the user to press Enter, before displaying 'World'.

Would this solve your problem?
 
kalyan at tcs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

i had nothing to input from user


bye

kalyan
 
Jason Fox
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is pretty ugly, and pretty much locks up the app, but you could do:
 
kalyan at tcs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jason Fox ,

thanks for ur help


bye

kalyan
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i was restricted not to use Thread concept


This is a rather vague restriction. Does this mean you can't use threads? If so, you can't start a JVM (which uses threads), and therefore, the problem is outside the scope of Java.
Does it mean you can't use the java.lang.Thread API? If so, perhaps your teacher is hinting at the use of Object wait/notify/notifyAll.

It is important to note that you can NEVER have a thread pause for a specific period of time - you can however, have a thread pause for at least a specific period of time. When that thread comes out of 'sleep' state it is put into 'ready for execution' state - not 'running' state. It is up to the indeterminate thread scheduler to decide when the thread is shifted to 'running' state.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!