[concurrency-interest] 100% cpu usage on winXP

Kasper Nielsen news@kav.dk
Tue, 24 Feb 2004 16:41:53 +0100


Hi,

Im having a problem with 100 % cpu usage on a windows platform, both on 
beta1 and beta1 + newest jsr166.jar

I've included a test case.

try running it first with
 > java Tester
and then
 > java Tester 100

The latter run should result in 100 % cpu usage on windows

regards
   Kasper
-------------------------------
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;

public class Tester implements Runnable
{
     private static final Callable NULL_CALLABLE = new Callable() {
         public Object call() throws Exception
         {
             return null;
         }
     };

     private SetFutureTask future;

     public Tester(SetFutureTask future) {
         this.future = future;
     }

     public static void main(String[] args) throws Exception
     {
         SetFutureTask future=new SetFutureTask();
         new Thread(new Tester(future)).start();
	if (args.length>0 && args[0].equals("100"))
           future.get();
         System.out.println("Start taking");	
         new LinkedBlockingQueue().take();
     }

     public void run()
     {
         future.set(new Object());
     }

     private static class SetFutureTask extends FutureTask
     {
         private SetFutureTask() {
             super(NULL_CALLABLE);
         }
         protected void set(Object arg0)
         {
             super.set(arg0);
         }
     }
}
---------------------------