Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 546 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 442 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
How do I implement a Timed thread in Java 8?

Hello,
I hope this is the correct forum. (Java 8?)
Anyway, how would I start to implement this code with Java 8:
public static void main(String[] args) {
Wait wait = new Wait(10000); //wait for ten seconds
try
{
wait.StartWait(); //return immediately
Thread.sleep(11000);
wait.StopWait();
}
catch (Exception ex)
{
System.out.print("Timer timed out.");
}
System.out.print("Success!");
}
Again, I need to return immediately from the StartWait method.
Thank you.
williamj
Best Answer
-
In order to create a thread in java you instantiate an Object of - java.lang.Thread class.
Now in the constructor of that object you need to provide -Runnable Type.
Runnable is an interface in Java. Go and implement it in your class and override the public void run(){} ..
That it Folks!!!
Answers
-
-
Hi 3192389,
In order to multithread you must extend the Thread class or implement Runnable:
public class YourThread implements Runnable{
}
-or-
class YourThread extends Thread {
}
Then of course define components and behavior within the class, and utilize them in the main class. Your code appears to include an invalid method: "startwait()"
Separate this into:
-start()
-notify() //to resume
Also, utilize setPriority() to ensure the threads conform to your design. If you need a more detailed explanation, let me know, and I will provide sample code.
Best,
Sam D.
-
In order to create a thread in java you instantiate an Object of - java.lang.Thread class.
Now in the constructor of that object you need to provide -Runnable Type.
Runnable is an interface in Java. Go and implement it in your class and override the public void run(){} ..
That it Folks!!!