I have a multi thread application built on Java and I need to set different priorities to this threads. In windows it works fine, a bigger value (priority) gets more CPU ... |
How are the java API thread priorities (1-10) gets translated to the OS level priorities since most OS don't have thread priority levels (in terms of number) which match this.
So keeping ... |
all threads have its priority,so what is the integer value for main thread?
|
I have a program that runs in a few threads. The main thread shares an object with the other threads and in the main I have a call to:
synchronized(obj){
...
|
As we know in java we have a priority levels for threads, and Garbage collector is a thread with lowest priority. So i wanted to know whether for a particular java ... |
To make an application in Java under Linux with threads if I wanted to
set a priority level which are min and max values?
In Windows the ranges goes form 0 (lowest) ... |
As we know that even main is also a thread. So just for the curiosity, is it possible to set the priority for the main thread?
|
|
Lets pretend I have two threads running in a program. Both threads reach a node(like in a tree or map) in which the user must enter data in order for the ... |
I have been asked in an interview the following question:
"What is the default priority of the Garbage Collection thread?"
I know we cannot force a GC or change its priority, though I ... |
i create a new thread like this:
Runnable r=new Runnable() {
public void run() {
// content
}
}
...
|
i am bit confused about need and usage of yield method . First of all my question is that if we have two thread of different priority in runnablestate does jvm ... |
Will Thread priority increases accuracy of Thread.sleep(50);?
As we know Threads aren't accurate when you call sleep for 50ms, But does it increases accuracy by any mean? If thread is listed ... |
I tried the following code, setting two different priority, one is 6 the other is 9, why the one with 6 is executed before the one with 9? It seems the order is decided by the order I call start(). Pls. give me some help if you know the reason. public class CounterThread extends Thread{ public static void main(String[] args){ CounterThread ... |
I tried the following code, setting two different priority, one is 6 the other is 9, why the one with 6 is executed before the one with 9? It seems the order is decided by the order I call start(). Pls. give me some help if you know the reason. public class CounterThread extends Thread{ public static void main(String[] args){ CounterThread ... |
Hi all, I've a question. suppose there are a number of threads in a program. each having different priority. now if i run this program on a m/c that uses time slicing as the scheduling algo. then will the priority of threads matter? In my opinion the answer is -- no I feel that all the threads will get equal CPU ... |
16. priority coderanch.comclass source { int even=0,odd=1; String s; public void print() { s=Thread.currentThread().getName(); if(s.equals("even")) { System.out.println(even); even+=2; } if(s.equals("odd")) { System.out.println("\t"+ odd); odd+=2; } try { Thread.sleep(500); } catch(Exception e) { } } } public class multi implements Runnable { Thread t1,t2; source c; public multi(){ t1=new Thread(this,"odd"); t1.setPriority(3); t1.start(); t2=new Thread(this,"even"); t2.setPriority(7); t2.start(); } public void run() { c=new source(); while(true) ... |
Depending on which JVM you use and what settings you give it, you may get "native" threads or "green" threads. With the former, you get whatever threading and prioritisation algorithm the platform likes. With the latter, you get a simple implementation of thread-like behaviour, actually on one platform thread. I can't remember the details of "green" threads, but it will be ... |
|
Hi,all: What is the default priority of a newly created thread. a MIN_PRIORITY (which is defined as 1 in the Thread class.) b NORM_PRIORITY (which is defined as 5 in the Thread class.) c MAX_PRIORITY (which is defined as 10 in the Thread class.) d A thread inherits the priority of its parent thread. why the anwser is not b but ... |
In a word, you can't. The fact is the Thread priority constants are implementation dependent, so a priority of 1, 2, and 3 may be identical on Windows and distint on Solaris. You could try to come up with an algorithm that would have each thread yield and sleep based on your arbitrary numbering but the behavior would not be consistent ... |
Consider the following code: class A implements Runnable{ public void run(){ i+=1; System.out.println("inside run"); } void printi(){System.out.println("i="+i);} volatile int i = 1; } public class Test{ public static void main(String[] args){// throws Exception{ A a= new A(); a.printi(); Thread t = new Thread(a); t.start(); a.i +=1; //Thread.sleep(1000); a.printi(); } } This code compiles well and gives the output: i = 1 ... |
Hi... I have a problem with threads. We have a web application that has its own logging object(for logging onto a log file or to console).And if I start another threads (for eg: to constantly write incoming messages onto a file etc), for some reason, the logger is not logging messages anymore either on to the console or to the log ... |
It tends to be a low priority task unless the JVM is seriously short on memory. As a last ditch effort, it will attempt to run garbage collection before throwing an OutofMemory error. The implementation is different based on the vendor though. [ February 07, 2006: Message edited by: Chris Allen ] |
|
/* Program to create multiple threads from a single class Author : Team -J Version : 1.0 */ class Thr3{ static public void main(String[] args)throws Exception{ Thread th1 = new MyThr3("thread one"); Thread th2 = new MyThr3("thread two"); Thread th3 = new MyThr3("thread three"); th2.setPriority(Thread.MAX_PRIORITY); th1.setPriority(Thread.MIN_PRIORITY); th3.setPriority(Thread.NORM_PRIORITY); th1.start(); th2.start(); th3.start(); } } class MyThr3 extends Thread{ // we are using a ... |
As your run() method does so little, one could not reasonably expect priority to have much effect. In fact, t1 may have started and finished, before the t2.start() statement even runs. As previous poster has pointed out, Java makes few promises about exactly what thread priorities will do. This is to accommodate different platforms. In practice, however, JVMs on major OSs ... |
i have a question about how threads and setting their priority works. I am playing with this code now on sun jdk 1.5 on linux: public class App { public static void main(String[] args) { Runnable r = new MyRunner(100); Thread t1 = new MyThread(r, "t1"); Thread t2 = new MyThread(r, "t2"); Thread t3 = new MyThread(r, "t3"); t1.setPriority(Thread.MAX_PRIORITY); t1.start(); t2.start(); ... |
The client has a JTree component, originally it loaded all the data from server. In that case, the user needs to wait a while before the main frame visible. So I decide to load the data dynamically. When createGUI, I just load the first level data, then show the main frame to the user. At that time, I start a SwingWorker ... |
Hi, To invoke the garbage collector explicitly we use Runtime.getRuntime().gc() But what is the priority of garbage collector thread? I have heard it runs on a low priority if there are multiple threads running which are creating a lot objects simultaneously then even if i invoke GC thread it doesn't get so much CPU time and objects doesn't get collected and ... |
Hi All, In my Solaris(4 CPU) box there are multiple JVMs are running to serve different components of the application. Due to several design holes most of these components are consuming max CPU. Now I am planning to reduce the priority of thread execution in one of the least used component to release CPU for those other JVMs/Components to process faster. ... |
|
|
Thread control is OS specific, the operating system chooses which Thread should get CPU cycles when. By setting the priority you give the OS a hint that Threads with higher priority should get more CPU cycles than Threads with lower priority. It is not something you can easily test with short-running Threads that don't hog CPU cycles. For example, in your ... |
34. priority coderanch.comhttp://stackoverflow.com/questions/297804/thread-api-priority-translation-to-os-thread-priority Solaris * 1 0 * 2 32 * 3 64 * 4 96 * 5 10 127 Of note is that on Solaris, you can't raise the thread priority above normal, only lower it: the priority value for 5 is the same as any of the higher values. Linux * 1 10 ... |
Hi, I have a class called as MessageHandler in which a method of another class MessageClient is called. MessageClient is a class which reads and writes to a socket. It sends a message, spawns another thread (say A) to read it, once the message is read it spawns another thread (say B) to process it. The processing might take long. So ... |
Hi Ranchers, Look athe code below /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author nkan */ class Runner implements Runnable { int i; public void run() { for(i=1;i<=50;i++) { System.out.println(i+" : "+Thread.currentThread().getName()); } } } /* * To change this template, choose Tools | Templates * ... |
|
class A implements Runnable{ public void run(){ System.out.println(Thread.currentThread().getName()); } } public class Test { public static void main(String... args) { A a = new A(); Thread t = new Thread(a); Thread t1 = new Thread(a); t.setName("t"); t1.setName("t1"); t.setPriority(10); t1.setPriority(3); t.start(); t1.start(); } } 1) What does the integer number for thread priority mean in here ? Does 10 mean that it ... |
i am bit confused about need of yield method .Yield method Causes the currently executing thread object to temporarily pause and allow other threads(of higher priority or same priority) to execute. At one of the article given at http://oreilly.com/catalog/expjava/excerpt/index.html it is given at If, at any time, a thread of a higher priority than the current thread becomes runnable, it preempts ... |
But Why low is executing count more then High thread despite low priroty is low Code: class clicker implements Runnable { int click = 0; Thread t; private volatile boolean running = true; public clicker(int p) { t = new Thread(this); t.setPriority(p); } public void run() { while (running) { click++; } } public void stop() { running = false; } ... |
import javax.swing.*; import java.awt.*; public class Test4 extends JFrame { public Test4() { super("Test Toolkit"); setSize(700, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); FlowLayout beginButtons = new FlowLayout(); setLayout(beginButtons); JLabel startLabels = new JLabel("Current System"); TimePanel time = new TimePanel(); add(startLabels); add(time); setVisible(true); } public static void main(String[] args) { Test4 StartWindow = new Test4(); } } |
Why don't you try it and see? I would guess that if you tried setting the priority after calling start() it would be just as if you had openned up the Task Manager (for Windows) and set the priority of a currently ready-state thread or process. As for a higher (or even a lower) setting than is allowed, Java either ignores ... |
|
|
Hi, Can a thread priority can be 0(zero).If so how does it behaves. As in java thread priorities start's from 1-10. As we say demonthread is the thread which runs with low priority i.e priority 1 which is min_priority. Then what a thread with priority 0 will make the thread to run or not. Thanks LeoSun |
In my project, i have to offer differentiated QOS to clients in an e-commerce application.. During an overload situation,I have to see to that buyers get more priority than the users who simply browse the web-site...I am using jsp,tomcat server,linux...Someone please give me idea how i have to assign more priority to the buy page.....How to consider that particular url and ... |
i have picture that when i go right created communication to the internet in order to import new data. the communication to the internet blows the movement on the screen. how can I set low Priority to the internet thread - i use this: thread.setPriority(1); but it not help - my picture get stuck - what to do? |