About 3,450,000 results
Open links in new tab
  1. How to set a Timer in Java? - Stack Overflow

    Oct 19, 2017 · Timer timer = new Timer(); To run the task once you would do: timer.schedule(new TimerTask() { @Override public void run() { // Your database code here } }, 2*60*1000); // Since Java-8 timer.schedule(() -> /* your database code here */, 2*60*1000);

  2. How to Handle Exceptions in Java Timer Tasks Without Stopping …

    Implement a custom exception handling mechanism that ensures the Timer remains active even if a task fails. Consider using a ScheduledExecutorService instead of Timer, as it provides better error handling and concurrency.

  3. Java Timer class: timer tasks stop to execute if in one of the …

    Jan 5, 2012 · Using ExecutorService; you can handle both compile time and run exceptions. Thread wt = Thread.currentThread(); Runnable task = w.firstTask; w.firstTask = null; w.unlock(); // allow interrupts. boolean completedAbruptly = true; try { while (task != null || (task = getTask()) != null) { w.lock(); // If pool is stopping, ensure thread is interrupted;

  4. java - Throw exception in TimerTask to another method - Stack Overflow

    Nov 5, 2013 · I want to throw the following exception to another method, but I don't know how to achieve this correctly. public void startTimeoutHandler() throws TimeoutException { timer = new Timer(); timerTask = new TimerTask() { @Override public void run() { throw new TimeoutException(); } }; }

  5. Java.util.Timer Class in Java - GeeksforGeeks

    Nov 14, 2021 · Timer class provides a method call that is used by a thread to schedule a task, such as running a block of code after some regular instant of time. Each task may be scheduled to run once or for a repeated number of executions.

  6. throw and throws in Java - GeeksforGeeks

    Apr 8, 2025 · The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. We can throw either checked or unchecked exception . The throw keyword is mainly used to throw custom exceptions.

  7. Java Exception Handling - GeeksforGeeks

    Mar 25, 2025 · Exception handling in Java is an effective mechanism for managing runtime errors to ensure the application’s regular flow is maintained. Some Common examples of exceptions include ClassNotFoundException, IOException, SQLException, RemoteException, etc.

  8. Exception Handling in Java - Baeldung

    May 11, 2024 · In this tutorial, we’ll go through the basics of exception handling in Java as well as some of its gotchas. 2. First Principles. 2.1. What Is It? To better understand exceptions and exception handling, let’s make a real-life comparison. Imagine that we order a product online, but while en-route, there’s a failure in delivery.

  9. How to Throw Exceptions in Java - Rollbar

    Feb 12, 2019 · Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception includes a message which is a human-readable error description.

  10. How To Throw Exceptions In Java Using throw, throws Keywords | Throwing

    Jul 1, 2023 · There are two ways you can obtain a Throwable object: using a parameter in a catch clause, or creating one with the new operator. The flow of execution stops immediately after the throw...

  11. Some results have been removed
Refresh