Results 1 to 6 of 6

Thread: Manage time in java

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Manage time in java

    Hello,
    I have a swing application which expects the inclusion of a USB key. If the user does not insert the USB key after two minutes of waiting I'd like the application continues to wait. So a timeoutqueue is what I want. I tried the java.util.Timer but I do not know what to use as a method. I wonder if that is the right object that I use. How to manage time in java. Could you help me?

  2. #2
    Join Date
    Nov 2009
    Posts
    359

    Re: Manage time in java

    Hello,
    For the principle at the beginning you put a flag to false for example, then when he entered the key you have is true, then a timer after two minutes you compare the flag if it is false it has always it has not brought the key in these cases you do the recommended actions. Timer for it surely must be some java code, may be a sleep or wait or delay.

  3. #3
    Join Date
    Dec 2009
    Posts
    292

    Re: Manage time in java

    Hello,
    I am new to java, that is at intermediate level. But I have a code which is related to your query, if you need you can try it out
    Code:
    		boolean prs =false;/ / boolean indicating if the key is found
                              long tm = System.currenttmMillis();/ / time of departure
    		long en = time + 18000;/ / en time
    		
    		
    		
    		 while ( (en> System.currenttmMillis())&& (prs ==false) ): / loop as key undetected and timeout not reached 
    		 {
    	
    		     prs = r.verif_presence_cle(stletter);
    		
    		 }

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Manage time in java

    Hello,
    For the principle it is ok I have already done in PHP. Otherwise I do not know how to determine my version of java. I did java-version in my console and it tells me java version 1.6. I have the correct version for the class m for help or I do tiemout gallery?Actually my version is 1.6.0_02 I just put my jvm to date. Still it is not working, if you have any ideas about it then i am interested.

  5. #5
    Join Date
    Nov 2009
    Posts
    343

    Re: Manage time in java

    Hello,
    I think you can try this code.
    Code:
     
    long st = System.currentTimeMillis();
      		
    while((System.currentTimeMillis() - Home) < 18000) {
    	your code
    }
     
    if ((System.currentTimeMillis() - Home) > 18000) {
    	System.out.System.out.println("Error: TIMEOUT");					
    	return;
    }
    Hope this help you out from your problem. If you have any more queries then feel free to ask.

  6. #6
    Join Date
    Nov 2009
    Posts
    335

    Re: Manage time in java

    Hello,
    I think the above is correct I have not tried it, but this code is much more efficient. Just check it out.
    Code:
    Object sn = new Object();
    boolean nus = true;
    
    Thread tmtsk = new Thread()
    {
      Public void run()
      {
        snhronized(snc)
        {
          try
          {
             sn.wait(tonTimeout);
          } catch (Exception e) {}
        }
       
        if (nus) { ... }
      }
    }
     
    / / To insert the key you do
    nus = false
    sn.notifyAll();

Similar Threads

  1. How to manage more than 2 sites with full time job
    By MODESTY in forum Technology & Internet
    Replies: 6
    Last Post: 19-02-2012, 12:49 PM
  2. Java code to manage book accounts
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 26-02-2010, 04:57 AM
  3. How to Manage Metadata in Java?
    By NIcaBoy in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 03:38 AM
  4. Computing Elapsed Time in Java
    By Linoo in forum Software Development
    Replies: 4
    Last Post: 18-02-2010, 07:39 PM
  5. Formatting time using java.util
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 03:21 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,104,596.98933 seconds with 17 queries