Posts

Showing posts with the label scheduled-tasks

Thread.sleep another class

Image
Clash Royale CLAN TAG #URR8PPP Thread.sleep another class I have a class, which inserts values in a database (e.g. insertdb.java). But I only want them to be inserted every full hour, so after a little bit of researching and trying different approaches, I tried it with a Thread.sleep. How can I implement this code with the insertdb.java class (not a method)? Thanks in advance for your tips! import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class thread { public static void main(String args) { ScheduledExecutorService t = Executors.newSingleThreadScheduledExecutor(); t.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { Thread.sleep(3600000); } catch (Exception e) {} } }, 0, 1, TimeUnit.HOURS); } } 1 Answer 1 ...