Performance wise which is best extends Thread Class or implement Runnable

Hi,
Which one is best performance wise extends Thread Class or implement Runnable interface ?
Which are the major difference between them and which one is best in which case.

Which one is best performance wise extends Thread Class or implement Runnable interface ?Which kind of performance? Do you worry about thread creation time, or about execution time?
If the latter, then don't : there is no effect on the code being executed.
If the former (thread creation), then browse the API Javadoc about Executor and ExecutorService , and the other execution-related classes in the same package, to know about the usage of the various threading/execution models.
If you worry about, more generally, throughput (which would be a better concern), then it is not impacted by whether you have implemented your code in a Runnable implementation class, or a Thread subclass.
Which are the major difference between them and which one is best in which case.Runnable is almost always better design-wise :
- it will eventually be executed in a thread, but it leaves you the flexibility to choose which thread (the current one, another thread, another from a pool,...). In particular you should read about Executor and ExecutorService as mentioned above. In particular, if you happen to actually have a performance problem, you can change the thread creation code with little impact on the code being executed in the threads.
- it is an interface, and leaves you free to extend another class. Especially useful for the Command pattern.
Edited by: jduprez on May 16, 2011 2:08 PM

Similar Messages

  • Performance wise which is better NOT IN or NOT EXISTS

    Performance wise which is better NOT IN or NOT EXISTS.

    also that not exists is not equivalent to not in
    SQL> select * from dept where not exists (select * from emp where dept.deptno=comm);
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> select * from dept where deptno not in (select comm from emp);
    no rows selectedin most case, Oracle internally rewrite a NOT IN in a NOT EXISTS, because NOT EXISTS usually performs better.
    HTH
    Laurent

  • Reflect the class that implements Runnable

    Hi,
    I am implementing the reflection of the class that implements Runnable. In order to start a new thread I am trying to invoke "start()" method ( which is obviously not defined my class ) and I therefore I am getting "java.lang.NoSuchMethodException".
    I am wondering is it possible at all to start a new thread on a reflected class?
    thanks in advance.
    {              Class refClass = Class.forName(className);
    String methodName = "start";
    Class[] types = new Class[1];
    types[0] = Class.forName("java.util.HashMap");
    Constructor cons = refClass.getConstructor(types);
    Object[] params = new Object[5];
    params[0] = new HashMap();
    Method libMethod = refClass.getMethod(methodName, null);
    libMethod.invoke(objType, null); }

    Well, if we knew what it meant to "start a thread on a class" we could probably figure out how to "start a thread on a reflected class". If we knew what a "reflected class" was, that is.
    In other words, it would help if you rephrased your question using standard terminology (and also explained why you want to do whatever it is you want to do).
    But let's guess for now: If you have an object which implements Runnable then you start a thread to run that object like this:
    Runnable r = // some object which implements Runnable
    new Thread(r).start();Not what you wanted? Go ahead and clarify then.

  • Implementing Runnable interface  Vs  extending Thread class

    hi,
    i've come to know by some people says that Implementing Runnbale interface while creating a thread is better option rather than extending a Thread class. HOw and Why? Can anybody explain.?

    Its the same amount of programming work...
    Sometimes it is not possible to extend Thread, becuase your threaded class might have to extend something else.
    The only difference between implementing Runnable and extending Thread is that by extending Thread, each of your threads has a unique object associated with it, whereas with Runnable, many threads share the same object instance.
    http://developerlife.com/lessons/threadsintro/default.htm#Implementing

  • Creating thread by extending thread class?

    HI
    What is the differnce in run() method in the thread class and
    public void run() method in ruble interface is both are same or saparete?
    is the run() method in the Thread class overridden method from Runnable interface?
    Thns

    It's a difference in paradigm. If you are changing the behaviour of how Thread works, extend from Thread.
    If you're implementing a system where you're using Thread instances to control some process, implement Runnable.
    In the vast majority of cases, that means you'll be implementing Runnable.
    The exception might be if you're writing an application server, or a process manager of some sort.

  • Question about methods in a class that implements Runnable

    I have a class that contains methods that are called by other classes. I wanted it to run in its own thread (to free up the SWT GUI thread because it appeared to be blocking the GUI thread). So, I had it implement Runnable, made a run method that just waits for the thread to be stopped:
    while (StopTheThread == false)
    try
    Thread.sleep(10);
    catch (InterruptedException e)
    //System.out.println("here");
    (the thread is started in the class constructor)
    I assumed that the other methods in this class would be running in the thread and would thus not block when called, but it appears the SWT GUI thread is still blocked. Is my assumption wrong?

    powerdroid wrote:
    Oh, excellent. Thank you for this explanation. So, if the run method calls any other method in the class, those are run in the new thread, but any time a method is called from another class, it runs on the calling class' thread. Correct?Yes.
    This will work fine, in that I can have the run method do all the necessary calling of the other methods, but how can I get return values back to the original (to know the results of the process run in the new thread)?Easy: use higher-level classes than thread. Specifically those found in java.util.concurrent:
    public class MyCallable implements Callable<Foo> {
      public Foo call() {
        return SomeClass.doExpensiveCalculation();
    ExecutorService executor = Executors.newFixedThreadPool();
    Future<Foo> future = executor.submit(new MyCallable());
    // do some other stuff
    Foo result = future.get(); // get will wait until MyCallable is finished or return the value immediately when it is already done.

  • Assigning ThreadGroup to a Class that Extends Thread

    How can i assign a thread group to a class running as a thread that extends thread without changing the class to implement Runnable?
    An Example of the application format:
    public class Application implements Runnable
    private ThreadGroup main = new ThreadGroup("Main");
    private Thread mainThread = null;
    public Application()
    public void start()
    if (mainThread == null)
    mainThread = new Thread(main,"main")
    mainThread.start();
    public void run()
    Thread current = Thread.currentThread();
    while(current != null)
    while(something to do)
    AThread a = new AThread();
    a.start();
    String aData = a.getData();
    BThread b = new BThread(data);
    b.start();
    String bData = b.getData();
    class AThead extends Thread
    public AThread()
    //What to do with AThread to assign it to a thread group?
    public void run()
    Basically the application works form a main constructor class running the application class as a thread. The application class will then launch AThread and BThread as subthreads. I would like to be able to count how many of each type of thread is running for the AThread and BThread. I tried using AThread and BThread implementing Runnable to create a thread under a group but it wouldn't work. The application class needs to get information from the AThread and BThread threads once the thread was done, but if the AThread and BThread was implementing Runnable, the Applicaiton Class can't get the data or run methods. Is there some way i can assign what thread group AThread and BThread will run as in thier class files and not the Application class?

    See: http://java.sun.com/j2se/1.4/docs/api/java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.String)
    I think this does what you want:
    public class Application implements Runnable
    private ThreadGroup main = new ThreadGroup("Main");
    private ThreadGroup aThreads = new ThreadGroup("AThreads"); // Added a thread group for all AThread objects
    private Thread mainThread = null;
    public Application()
    public void start()
      if (mainThread == null)
        mainThread = new Thread(main,"main")
        mainThread.start();
      public void run()
        Thread current = Thread.currentThread();
        while(current != null)
          while(something to do)
            AThread a = new AThread(aThreads);  // Create an AThread that will belong to aThreads ThreadGroup
            a.start();
            String aData = a.getData();
            BThread b = new BThread(data);
            b.start();
            String bData = b.getData();
    class AThead extends Thread
      public AThread(ThreadGroup group)
        super(group, "AThread"); // This will make a new Thread that belongs to ThreadGroup group, see link above
      public void run()
    }

  • Thread Pool Executor ( Runnable Class Executing another Runnable Class )

    Hi Folks,
    I have my main class called ThreadPoolExecutorUser. I have two Runnable classes called XYZ and ABC
    in ThreadPoolExecutorUser class I execute the Runnable class XYZ. Which inturn executes Runnable class ABC.
    The problem is that the Runnable class ABC is never executed ?. Can some one please explain what I am I doing wrong.
    _RB
    More Description Below :
    *public class ThreadPoolExecutorUser {*
    ThreadPoolExecutor dude = new ThreadPoolExecutor (.... );
    // I Execute the firest Runnable Xyz here
    dude.execute ( XYZ );
    Now I have two Runnable inner Classes
    *Class XYZ extends Runnable {*
    public void run () {
    s.o.p ( " I am in Xyz Runnable " );
    dude.execute ( ABC );
    *class ABC extends Runnable {*
    public void run () {
    s.o.p ( " I am in ABC Runnable " );
    }

    Hey folks.... Sorry its a typo in my e-mail. Sorry about that. I am pasting the actual code here.
    The problem again is that in the index function only FirstRunnable executes but not the SecondRunnable
    final public class Crawler {
        / create an instance of the ISSThreadPoolExecutor /
        private static ThreadPoolExecutor mythreadpoolexecutor = ThreadPoolExecutor.getInstance();
        / Constructor /
        / Index function /
        public void index( .... ) {
            :::::: code :::::::::
            // Execute this folder in a seperate thread.
            this.issthreadpoolexecutor.execute(new FirstRunnable(alpha, beta, gamma));
        / The Inner Class /
        class FirstRunnable implements Runnable {
            public FirstRunnable(int alpha, int beta, int gamma) {
            public void run() {
                            doSomething();
                            // Some other tasks and ...spawn of another thread.
                            issthreadpoolexecutor.execute(new SecondRunnable(a));
             // The Inner Class that Indexes the Folder
              class SecondRunnable implements Runnable {
                      private int ei;
                      public SecondRunnable ( int abc ) {
                            this.ei = abc;
                      public void run() {
                            doSomething ( ".....") ;
              } // End of SecondRunnable Class.
         } // End of FirstRunnable class.
    } // End of Crawler Class.

  • 2 Questions How to use join() and Which is best coding pratice.

    Hi All,
    I have 2 Question:
    I have a MultipleThread class and when I try to use join method of thread class I get compile time error(so i commented it out).I also wanted to know is the best approch to write a threaded program.I also wanted to know about the best coding pratice for threadand also do I need to declare Instance variable thread and name(Is it possible to create multiple thread with out declaring instance variable thread and name , if yes which one is the better way 1> with instance variable 2> with out instance variable)

    Sorry here is the code.
    package javaProg.completeReferance;
    public class MultipleThread implements Runnable
         Thread thread;
         String name;
         MultipleThread(String nam)
              this.name=nam;
              thread = new Thread(this,name);
              thread.start();
         public void run()
              try
                   for (int i=1;i<=10;i++ )
                        Thread.sleep(1000);
                        System.out.println("Thread "+name+" "+i);
              catch (InterruptedException e)
                   System.out.println(""+e);
         public static void main(String [] args)
              try
                   MultipleThread t1=new MultipleThread("One");
                   MultipleThread t2=new MultipleThread("Two");
                   MultipleThread t3 =new MultipleThread("Three");
                   //t1.join();
                   //t2.join();
                   //t3.join();
                   for (int i=1;i<=10;i++ )
                        Thread.sleep(1000);
                        System.out.println("Parent Thread "+i);
              catch (InterruptedException e)
                   System.out.println(" "+e);
    }

  • Implements Runnable vs extends Thread

    Hello,
    Why do we call method run() in a Runnable class a thread? (at least my textbook implies such concept)
    If thread is an independent process, which runs on its own - then it's not about Runnable.run().
    public class RunnableThread implements Runnable
        public void run()
            for (int i=0; i<100000; i++)
                if (i%50000 == 0)
                System.out.print(i+" ");
        public static void main (String args[])
            System.out.println("Before thread");
            new RunnableThread().run();
            System.out.println("Thread started");// this line is executed only after
            // run() returns, not like with "true" threads, where execution course          
            //doesn't wait for start() to return
    }Or should I consider run() a regular (non-thread) method needed only to bypass extends restrictions?

    Why do we call method run() in a Runnable class a
    thread? We don't.
    (at least my textbook implies such concept)Perhaps you could post what your textbook says, and we can decipher it for you.
    If thread is an independent process, which runs
    on its own - then it's not about Runnable.run().Don't know what you mean by it being "about" Runnable.run()?
    Runnable.run is the method that gets executed when a thread is started.
    Or should I consider run() a regular (non-thread)
    method needed run() is a regular method. It happens to be one that is declared in the Runnable interface and is called by an executing thread. In your example code, you use just call run as you would any other method, so it acts just like any other method. To run it in a separate thread, you should call start() on the thread, not run(). The Thread object will then enter the waiting state and will call run() itself at the appropriate time.

  • Runnable Vs Thread Class

    Hello All,
    I have a doubt regarding Runnable and Thread class. As we all know Java provides two ways to run Threads. One way is to extend Thread class and the other way is to implement Runnable Interface.
    Apart from the OOPS funda, does java have any other concept in providing two ways to run threads ?. I mean, we very well know that if we extend Thread class, we may not be able to extend any other class in Java . So if we implement Runnable interface,we can extend or implement any other Interface or class. Apart from this reason, does Java has any other concept in providing two ways to run threads ??
    Please share your knowledge
    Thanks and Have a Nice Day,
    Regds,
    Sai

    As far as I know, that's the only reason for the two options--one gives you flexibility in your class hierarchy, the other saves you a few lines of code. Personally, I always implement Runnable. The few lines of code saved seem trivial to me compared to "cleaner" OO (IMHO), but maybe somebody else has a better reason to extend Thread.

  • Concrete classes implement abstract class and implements the interface

    I have one query..
    In java collection framework, concrete classes extend the abstract classes and implement the interface. What is the reason behind extending the class and implementing the interface when the abstract class actually claims to implement that interface?
    For example :
    Class Vector extends AbstractList and implements List ,....
    But the abstract class AbstractList implements List.. So the class Vector need not explicitly implement interface List.
    So, what is the reason behind this explicit definition...?
    If anybody knows please let me know..
    Thanx
    Rajendra.

    Why do you post this question again? You already asked this once in another thread and it has been extensively debated in that thread: http://forum.java.sun.com/thread.jsp?forum=31&thread=347682

  • Naming a thread that is created implementing Runnable

    How could I name a thread that I create using Runnable Interface?
    public class Test {
         * @param args the command line arguments
        public static void main(String[] args) {
            TestRunnable tr = new TestRunnable();
            /* running thread */
            new Thread(tr).start();//THREAD 3
    public class TestRunnable implements Runnable {
        public void run() {
            for(int y = 1; y < 1000; y++) {
                System.out.println("3333333333333333333333333333333333333333 " + Thread.currentThread() );
    }

    well, I'm just experimenting; learning about Threads. As you can see I
    was able to name the other two threads, I was just curious how you would do it,
    using the Runnable Interface, seeing as those two naming options I used don't
    seem to be an option for it. I may be misunderstanding your reply...
        public static void main(String[] args) {//thread 0
            FrameThread ft = new FrameThread();//extends Thread
            ft.setName("ft");
            Thread td = new Thread("td") {
                @Override
                public void run() {
                    for(int a = 1; a < 1000; a++) {
                        System.out.println("1111111111111111111111111111111111111111 " + Thread.currentThread() );
            TestRunnable tr = new TestRunnable();//class implements Runnable
            /* running threads */
            td.start();//THREAD 1
            ft.start();//THREAD 2
            new Thread(tr).start();//THREAD 3
    }I'm naming them so when I use : Thread.currentThread() the return slot has the name I provide.
    Edited by: rico16135 on May 3, 2008 3:14 PM
    Edited by: rico16135 on May 3, 2008 3:17 PM

  • Creating array of objects of class which extends Thread

    getting NullPointerException
    can i not create thread array this way?
    class sample extends Thread
    { int i,id;
      public sample(int c)
       { id=c;
      public void run()
      { for(i=0;i<6;i++)
         System.out.println("Thread "+id+" "+i);
    public class thread extends Frame implements ActionListener
    {  Button b1;
       sample s[];
       thread()
       { for(int i=0;i<2;i++)
              s=new sample(i);
         setLayout(new FlowLayout());
         b1=new Button("OK");
         add(b1);
         b1.addActionListener(this);
         public void actionPerformed(ActionEvent e)
         {   b1.setEnabled(false);
              for(int i=0;i<2;i++)
              { s[i]=new sample(i);
              s[i].start();
         public static void main(String args[])
         { thread t1=new thread(); 
         t1.setVisible(true);
         t1.setSize(150,150);

    You need:
    sample [] s = new sample[2];However
    1) You should get into the habit that class names start with capital letters, variable and field names with lower case.
    2) It's not a good idea to extend Thread, make a class which implements the Runnable interface and hook a standard Thread object to that.

  • Calls to methods in a class that extends Thread

    Hello,
    I have some code that I am initiating from within an ActionListener that is part of my programs GUI. The code is quite long winded, at least in terms of how long it takes to perform. The code runs nicely, however once it is running the GUI freezes completely until operations have completed. This is unacceptable as the code can take up to hours to complete. After posting a message on this forum in regard to the freezing of the GUI it was kindly suggested that I use multi-threading to avoid the unwelcome program behaviour.
    The code to my class is as follows:
    public class FullURLAddress
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    I have changed the above code to make use of multithreading by making this class extend Thread and implementing the run() method as follows:
    public class FullURLAddress extends Thread
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
      public void run()
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    /* What happens with these methods, will they need to have their
    own treads also? */
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    Are there any special things that I need to do in regard to the variables returned by the getCount() and xurlAddressDetails() methods. These methods are called by the code that started the run method from within my GUI. I don't understand which thread these methods are running in, obviously there is an AWT thread for my GUI and then a seperate thread for my FullURLAddress objects, but does this new thread also encompass the getCount() and xurlAddressDetails() methods?
    Please explain.
    This probably sounds a little wack, but I don't understand what thread is responisble for the methods in my FullURLAddress class aside of course from the run() method which is obvious. Any help will be awesome.
    Thanks
    Davo

    Threads are part of code that allows you to run multiple operations "simultaneously". "Simultaneously", because threads are not run actually simultaneously in any one-CPU machine. Since you most propably have only one CPU in your system, you can only execute one CPU instruction at time. Basically this means that your CPU can handle only one java-operation at time. It does not matter if you put some code in thread and start it, it will still take up all CPU time as long as the thread runs.
    So you would need a way to let other threads run also, for that purpose thread contains a yield feature that allows you to give time for other threads to run.
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Thread.html#yield()
    You need to use thread's yield() method in your thread code, in a place you want to give other threads time to run. Also bear in mind that if you yield your first thread run to allow second thread to run, you also need to add yield to the second thread also. If you don't, after yielding the first thread, the second thread will eat up all CPU time until it finishes, thus meaning the rest of your first thread will be run after second thread is done.
    One good place to execute yield() is usually at the end of a loop, for example 'for' or 'while' loop. This way you prevent for example while-deadlocks.
    Here is a java thread tutorial, worthy reading:
    http://java.sun.com/docs/books/tutorial/essential/threads/

Maybe you are looking for

  • Report Manager - ER 8530306: NEED USER TO VALUE SECURITY FOR PT EXPANSI

    Hi We are facing the above same gap in implementing report manager. I think it's one of the most common things that reports are run for parent segment GL values to have consolidated reporting in any large organisations. Hence PT(Page/Total) is requir

  • ITunes 11.0.3 installation failed, iPhone disappears from MacBook Pro

    Did the update of iTunes to version 11.0.3 some days ago. When finishing I got the message "an error occured", but the new version of iTunes was installed. Now I've got the problem, that my iPhone 5 is no longer recognized by my MacBook Pro. This mea

  • Object type with constructor gets PLS-00307 (10g)

    Hi all, I have the following code, and I am getting the following error. I want to have a constructor that can be called without specifying the parameters by name. Is that not possible? What am I doing wrong? Thanks! Error:Error at line 50 ORA-06550:

  • Can I acces the Windows DIB with an Imaq function

    I am trying to pass images between several applications, one of which is not a Labview program. I want to post an image as a windows DIB in this external program and then access it and display it in Labview.

  • Hyperion EPM 11.1.2 Performance tuning

    Hi Can any one let know performance tuning ofe Hyperion 11.1.2 Planning , BIPlus workspace and EAS as we are having issues of slowly running webforms, FR reports and Calc and BR taking time to open and run and login taking time. Thanks