Hi !

I tried to figure out system load with this piece of code:

        new Thread(new Runnable() {
                public synchronized void run() {
                    long[] average = new long[5];
                    int pos = 0;
                    long sum = 0;

                    while (true) {
                        try {
                            this.wait(1000);

                            long time = System.currentTimeMillis();
                            for (int i=0; i<100; i++) {
                                Thread.yield();
                            }
                            long value = (System.currentTimeMillis() - 
time);
                            System.out.println("Time: " + value);

                            sum -= average[pos];
                            average[pos] =  value;
                            sum += value;
                            pos = (pos + 1) % average.length;
                            System.out.println("Average: "
                                               + (sum / average.length));

                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();


And it seems to do a pretty good job on my VM (Sun 1.4/Linux), which 
doesn't necessairily mean it will give
good results in other environments (windows/kaffe etc.).

Niklas


_______________________________________________
Devl mailing list
Devl at freenetproject.org
http://lists.freenetproject.org/mailman/listinfo/devl

Reply via email to