Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Batch File???

Options
  • 27-05-2005 8:34pm
    #1
    Registered Users Posts: 6,315 ✭✭✭


    Don't know if that is the right term for it.

    I want my java console app to do something every five seconds until I tell it to stop. i.e. poll a mobile over serial port for new messages.

    It's been years since I even wrote a non GUI java app.

    Would this be achieved through case statements or what?


Comments

  • Closed Accounts Posts: 888 ✭✭✭themole


    threads using sleep , sounds like the easiest to me.

    lookup the api's


  • Registered Users Posts: 2,800 ✭✭✭voxpop


    yeah have your polling section in a seperate thread, then use thread.sleep(miliseconds)

    A better solution, if you have some of your own java code on the mobile is to fire an event which the client java app listens for. This way you are not continuously polling and only act when the event you are interested actually happens


  • Registered Users Posts: 4,287 ✭✭✭NotMe


    try {
       Thread.sleep(300000);
    }
    catch(InterruptedException ex) {
       ex.printStackTrace();
    }
    

    Wait for 300000 seconds = 5 minutes. Just put that in a loop with whatever else you want to do.


  • Registered Users Posts: 6,315 ✭✭✭ballooba


    What I meant was more how to stop it looping?

    [When I want it to stop of course, i.e. stop it in a controlled manner, would this be a case statement?]


  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    public class Foo extends Thread
    {
        private boolean stopped;
    
        public void run()
        {
            stopped = false;
            while(!stopped)
            {
                // poll your phone here
                Thread.sleep(300000);
            }
        }
    
        // can't call the method stop() cause that's a depreciated thread method
        public void end()  
        {
            stopped = true;
        }
    }
    
    That's the standard way for stopping a thread. Since they depreciated the stop method. The thread loops based on a boolean variable which can be changed by other threads. From your main class you start the thread, and wait for some user input like a certain key press. Then you call the end method.


  • Advertisement
  • Registered Users Posts: 6,315 ✭✭✭ballooba


    Thanks,

    I'll give that a go this afternoon.


Advertisement