Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Threads
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Threads and Synchronization
priortiy
abalfazl hossein
Ranch Hand
Posts: 635
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class SimpleThread extends Thread { public SimpleThread(String str) { super(str); } public void run() { for (int i = 0; i < 10; i++) { System.out.println(i + " " + getName()); try { sleep((int)(Math.random() * 1000)); } catch (InterruptedException e) {} } System.out.println("DONE! " + getName()); } } public class Main { public static void main(String[] args){ SimpleThread a=new SimpleThread("Jamaica"); a.setPriority(5); SimpleThread b=new SimpleThread("Jamaica"); b.setPriority(0); a.start(); b.start(); } }
When I run this code , this massage shows :
compile:
run:
Exception in
thread
"main" java.lang.IllegalArgumentException
at java.lang.Thread.setPriority(Thread.java:1015)
at priority.Main.main(Main.java:23)
Java
Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
How can I fix it?I use netbeans and windows
Ulf Dittmer
Rancher
Posts: 43081
77
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The priority value needs to fall into the range [Thread.MIN_PRIORITY, Thread.MAX_PRIORITY] - you're using a value that does not.
abalfazl hossein
Ranch Hand
Posts: 635
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You are right! I mistake!zero isn't
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Does this resolve the issue?
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to wait for multiple thread to finish run
Thread, Runnable interface, simple question
join()
thread class execution explanation required
Threads
More...