Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Java in General
Thread problem
Maki Jav
Ranch Hand
Posts: 473
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Why are these threads not processing?
public class TestSpeed{ public static void main(String [] args){ final String word=""; final String line=""; new Thread(new Runnable(){ public void run(){ rk(word,line); } }); new Thread(new Runnable(){ public void run(){ java(word,line); } }); try{ Thread.currentThread().sleep(1000); }catch(InterruptedException ie){} } public static void java(String word,String sentence){ long start = System.currentTimeMillis(); System.out.println(System.currentTimeMillis()-start); } public static void rk(String word,String sentence){ long start = System.currentTimeMillis(); System.out.println(System.currentTimeMillis()-start); } }
Help gets you when you need it!
Ulf Dittmer
Rancher
Posts: 43081
77
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Because their
start
method is never called. Constructing a
Thread
object does not start its execution.
Maki Jav
Ranch Hand
Posts: 473
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Oh! It should be...
public class TestSpeed{ public static void main(String [] args){ final String word=""; final String line=""; new Thread(new Runnable(){ public void run(){ rk(word,line); } }).[B]start[/B](); new Thread(new Runnable(){ public void run(){ java(word,line); } }).[B]start[/B](); try{ Thread.currentThread().sleep(1000); }catch(InterruptedException ie){} } public static void java(String word,String sentence){ long start = System.currentTimeMillis(); System.out.println(System.currentTimeMillis()-start); } public static void rk(String word,String sentence){ long start = System.currentTimeMillis(); System.out.println(System.currentTimeMillis()-start); } }
Thanks,
Maki Jav
Help gets you when you need it!
I am displeased. You are no longer allowed to read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Question about the join method in Thread
Countdown timer in java
Threads..join() method
when extend a class
Threads
More...