Solved

sleeping?

Posted on 1998-02-19
1
297 Views
Last Modified: 2010-04-16
How do you tell a Java application to sleep? For example I am talking to a serial device that need at least 300ms between commands?

I found a sleep method for a thread but I don't have a thread
0
Comment
Question by:micah
1 Comment
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 1233165
Of course you have a Thread, you are running aren't you?

import java.lang.Thread
;
public class Source1
{
      public static void main (String args[])
      {
            System.out.println("Hello World!!");
            Thread cT = Thread.currentThread();
            System.out.println("Starting sleep period");
            try{
                  cT.sleep(1000);
            }
            catch(InterruptedException e){
                  System.out.println("Leave me alone!");
            }
            System.out.println("Waking up");
      }
}
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now