For example if you schedule in Python you just have to import time, then do time.sleep(seconds)
and then your good to go. I've tried to do some similar things in Java, but it never worked.
Asked
Active
Viewed 74 times
-2

skelet0n
- 17
- 5
-
2Please show your latest non-working attempt at solving this problem. – vinS Dec 11 '17 at 03:22
-
`java.lang.Thread.currentThread().sleep(java.util.concurrent.TimeUnit.SECONDS.toMillis(seconds));` – Elliott Frisch Dec 11 '17 at 03:23
-
it looks like very similar to your problem. https://stackoverflow.com/a/24104427/9081600 – Prodian Dec 11 '17 at 03:24
-
Oh sorry, I'm new here. I tried doing `import java.time;` then I just did `System.time.sleep(seconds)` – skelet0n Dec 11 '17 at 03:24
-
You can't just make up stuff that looks like something you saw in another language. You have to actually read the documentation to see how it works in Java. – Jim Garrison Dec 11 '17 at 04:34
2 Answers
0
Can you try code sleep 3s :
public class Main {
public static void main(String[] args) {
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
System.out.println("Error");
}
}
}

huunhancit
- 119
- 1
- 3
-
It didn't work, it said: Main.java:13: error: unreported exception InterruptedException; must be caught or declared to be thrown Thread.sleep(3000); ^ 1 error – skelet0n Dec 11 '17 at 03:28
-
1`public class Main { public static void main(String[] args) { try { Thread.sleep(3000); } catch (InterruptedException ex) { System.out.println("Error"); } } }` please try run codea again – huunhancit Dec 11 '17 at 03:31
-
@huunhancit Please don't "correct" code by posting a comment, [edit] your original answer. – Jim Garrison Dec 11 '17 at 04:35
0
You can user class Timer java Ref: https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html Or use http://www.quartz-scheduler.org/

huunhancit
- 119
- 1
- 3