Skip to content
Advertisement

Tag: timer

How do you stop a java method execution with a timer?

I am trying to stop a long running method after 10 seconds of execution, so far i followed the timer instructions on baeldung. https://www.baeldung.com/java-stop-execution-after-certain-time#1-using-a-timer When the method is a simple call to a thread sleep it works, but when I call my function with sub methods it doesn’t stop. My implementation looks like this: And the way I am calling

Ending a timer using keyadapters?

So, I am creating this reaction time game that shows a blue ball and once you see that blue ball, you press up arrow key to get your reaction time once it turned blue. However, I am having trouble in creating a timer. I want the timer to start once the ball actually turns blue and want that timer to

How to pause and resum a timer in Java

I have a small game where I need to pause the timer when the user press Pause button and after to resume the timer and to continue to increase the seconds when the user press the Resume button. I researched a lot and I tried different solutions but none worked for me. Can you please help me to achieve this

CountDownTimer in Android using Java

I am trying to implement a timer in android. I am using the countdowntimer. Here, is the timer code: The timer keeps updating the amount of time left on the user’s screen. The problem is the timer keeps ending at 00:01 (1 second), it never displays 00:00 and the alarm tone rings 2 seconds after the timer ends. How can

ScheduledExecutorService or ScheduledThreadPoolExecutor

I’m building an Android App which have to periodically do something in a Service. And I found that using ScheduledThreadPoolExecutor and ScheduledExecutorService is preferable to Timer. Can anyone explain the difference between ScheduledExecutorService and ScheduledThreadPoolExecutor and which one is more suitable for Android? Update I just found this article and this post explain the difference between several way to implement

How to stop Java Scanner from accepting input

So, I am working on a quiz taking program that works from the command line and the quizzes have time limits. What I want to do, is to stop the quiz right when the user’s time is up even if they’re in the middle of answering a question. I am using Java’s Scanner to get the user’s input, so I

TimerTask class has to run only once in java

I have a class that runs for every 10 secs, but when I execute it more than once, multiple timers are started. If one timer is already running, I want the other timer calls to be ignored. I want only one timer to be running at a given point of time. Please help. My code: Answer I want the 1st

Java: Using Semaphore with timer

Hello im trying to synchronize classes using semaphore.acquire() and semaphore.release(). I’m calling semaphore.release() from a class named ReadSerialPort and semaphore.acquire() from WriteSerialPort to connect a phone-center to PC. My problem is that phone-center is not always responding. I would like to know a way to set timer and make semaphore.release() after the time has past. P.S: I tried using TimedSemaphore

Advertisement