Results 1 to 8 of 8

Thread: Problem using Java.util.Timer

  1. #1
    Join Date
    Jan 2010
    Posts
    99

    Problem using Java.util.Timer

    I am doing a Java program using a timer. Searching the web I found that I can use either or java.util.Timer javax.swing.Timer. Well, I intend to create a timer which, when you press a button starts to count time, and when you press another stop, so if you press the first button again to continue the timer. It is not necessary where the timer is going, and I do not intend to count numbers or anything like that, I better start with the timer again, as I only want to count the seconds and tell me every second to perform an action determined. When I start the timer all goes smoothly, the problem comes when I press the button to stop it and I want to restart it again by pressing the first button again returns you to "activate", so to speak. In doing so, the timer does not stop, continues to send signals to the ActionListener, because I put a System.out.println ("Here comes the temp.") And shows me forever. I think that I may be doing things wrong because not having that much idea about the Java.util.Timer. So I am expecting some explanation from your side about the Java.util.Timer.

  2. #2
    Join Date
    Apr 2008
    Posts
    193

    Re: Problem using Java.util.Timer

    I think that you should know about the Timer Class. Once you get the basic things about this class then you can do the changes accordingly. Timer Class supplies a method for executing a technique at specified intervals. This class cannot be inherited. Use a timer callback allot to identify the method you want the timer to execute. The timer delegate is specified when the timer is raised, and cannot be changed. The method does not implement in the thread that created the timer, it executes in a thread pool thread supplied by the system. When you generate between on a timer, you can specify quantity of time to remain before the first execution of the method (due time), and an amount of time to wait subsequent executions (period). You can amend these values, or immobilize the timer, using the Change method.

  3. #3
    Join Date
    Jan 2010
    Posts
    79

    Re: Problem using Java.util.Timer

    I have a little doubt about how the timmer, I am sending files from one pc to mobile using bluetooth, but I found a problem when the message reaches the phone, they ask if they accept the message or not, depending on each manufacturer is a time limit for making the decision, some are 60 seconds in, as in other unfortunately time waits for a permanent, communication is done using Http_Obex protocols, but unfortunately still not well implemented find yourself in a timeout, then a piece of code implement a timmer. Please help me out.!!

  4. #4
    Join Date
    Oct 2008
    Posts
    167

    Re: Problem using Java.util.Timer

    depending on each manufacturer is a time limit for making the decision, some are 60 seconds in, as in other unfortunately time waits for a permanent, communication is done using Http_Obex protocols, but unfortunately still not well implemented find yourself in a timeout, then a piece of code implement a timmer.
    Is there any code that you are trying.?? From your question, I think that you are using some kind of code. It would be better if you provide that code with your exact queries. It would be understandable for me (also others..) with that code. If you are looking for quick response then provide the coding sooner.

  5. #5
    Join Date
    Jan 2010
    Posts
    79

    Re: Problem using Java.util.Timer

    Thanks for the quick reply. Also I apologize for not asking my problem properly. The question I have is that I need something like the timmer but with modifications such as :
    Code:
    Timer timer = new Timer (3000, new ActionListener () 
    ( 
    
    public void actionPerformed (ActionEvent e) 
    ( 
    / / / Here is what I want to do 
    ) 
    
    try 
    ( 
    Thread.currentThread (). Sleep (17000); 
    ) Catch (Exception J) 
    ( 
    )
    I understand the above code that makes the action every three seconds depending on what is in the method public void actionPerformed (ActionEvent e) until there are 17 seconds .. My question is how to implement something like this that not every three seconds if there is a limit to take the decision by the client to accept or reject the message and disconnect at this time. So give some time to do what makes to do and if not disconnected. If you can guide me I would be very grateful.

  6. #6
    Join Date
    Dec 2008
    Posts
    202

    Re: Problem using Java.util.Timer

    I do not quite understand the code, I imagine missing keys or something. java.awt.Timer released only after three seconds and ends. If you want to do something every three seconds, you have to call every time you finish to restart. For this type of thing, perhaps more reliable java.util.Timer. That does allow that automatically skip every 3 seconds from 17 seconds or whatever. If the operator does have to do, you can abort the timer by calling the method cancel (). I hope that you will find some other way.

  7. #7
    Join Date
    Jan 2010
    Posts
    79

    Re: Problem using Java.util.Timer

    hi thanks for replying, the idea is not to give an initial time, but if a final time, for example the customer has 15 seconds to accept the submitted file, it's so, determine a time frame for the user to take a decision, if not out and not send anything .. What three seconds is to give you a little illustration, because with that example every three seconds, running something, mine is simply cyclical than is from 0 to 15 seconds to do something if you do not cancel .. I hope you understood me. Thank you.

  8. #8
    Join Date
    Oct 2008
    Posts
    167

    Re: Problem using Java.util.Timer

    Look again and probe is not met within 15 seconds, you leave one and does nothing. Please check. I do not know where the error occurred. The method Send_Message (url); what it does is create a connection and send a file.
    Code:
     public static void time () throws IOException, InterruptedException 
    ( 
    try 
    ( 
    Timer timer = new Timer (15000, new ActionListener () 
    ( 
    
    public void actionPerformed (ActionEvent e) 
    ( 
    try 
    ( 
    
    / / String name 
    Send_Message (url); 
    ) 
    catch (Exception ex) 
    ( 
    ex.printStackTrace (); 
    ) 
    ) 
    )); 
    timer.start (); 
    / / Try 
    / / ( 
    / / Thread.currentThread (). Sleep (17000); 
    / /) Catch (Exception J) 
    / / ( 
    / /) 
    ) Catch (Exception o) 
    
    ( 
    ) 
    )

Similar Threads

  1. Error "java.util.Arrays.mergeSort (Unknown Source)"
    By Fragant in forum Software Development
    Replies: 7
    Last Post: 09-09-2010, 10:18 PM
  2. JRE can't see java.util.List
    By amreldeeb in forum Software Development
    Replies: 2
    Last Post: 21-02-2010, 03:31 PM
  3. Problem in java timer Class
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 12:48 AM
  4. Random number using java.util
    By New ID in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 02:22 AM
  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,713,541,251.98335 seconds with 16 queries