Académique Documents
Professionnel Documents
Culture Documents
Thread by implementing Runnable interface sample code examples - Java Sample Programs
Home Fundamentals Constructors Exception Handling Threads String Functions Generics Collections & Util Package Nested Classes Networking File I/O Operations Java Annotations JDBC Examples Java Interview Questions Java Interview Programs JUnit Search Algorithms Sorting Algorithms Data Structures JBoss Configurations
We can not declare top level class Java allows only public and default top level classes in java. Inner clas private.
} p u b l i cc l a s sR u n M y T h r e a d{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga [ ] ) { S y s t e m . o u t . p r i n t l n ( " S t a r t i n gM a i nT h r e a d . . . " ) ; M y R u n n a b l e T h r e a dm r t=n e wM y R u n n a b l e T h r e a d ( ) ; T h r e a dt=n e wT h r e a d ( m r t ) ; t . s t a r t ( ) ; w h i l e ( M y R u n n a b l e T h r e a d . m y C o u n t< =1 0 ) { t r y { S y s t e m . o u t . p r i n t l n ( " M a i nT h r e a d :" + ( + + M y R u n n a b l e T h r e a d . m y C o u n t ) ) ; T h r e a d . s l e e p ( 1 0 0 ) ; }c a t c h( I n t e r r u p t e d E x c e p t i o ni e x ) { S y s t e m . o u t . p r i n t l n ( " E x c e p t i o ni nm a i nt h r e a d :" + i e x . g e t M e s s a g e ( ) ) ; } } S y s t e m . o u t . p r i n t l n ( " E n do fM a i nT h r e a d . . . " ) ; } }
Find us on Facebook
Example Output
Starting Main Thread... Main Thread: 1 Expl Thread: 2 Main Thread: 3 Expl Thread: 4 Main Thread: 5 Expl Thread: 6 Main Thread: 7 Expl Thread: 8 Main Thread: 9 Expl Thread: 10 Main Thread: 11 End of Main Thread...
1,608 people like Java Sample Programs
What is generics wildcard argumen example. Write a program to find maximum words from a file.
www.java2novice.com/java_thread_examples/implementing_runnable/
1/2
2/14/14
Thread by implementing Runnable interface sample code examples - Java Sample Programs
How to zip a single file?
About Author
My name is Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment. If you come across any mistakes or bugs, please email me at java2novice@gmail.com or you can comment on the page.
Write a program to find maximum repeated words from a file. How to read file content using byte array?
Reference: Java Platform Standard Ed. 6 - API Specification | Java is registered trademark of Oracle. Privacy Policy | Copyright 2013 by Nataraja Gootooru. All Rights Reserved.
www.java2novice.com/java_thread_examples/implementing_runnable/
2/2