idlethread.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 68 行

JAVA
68
字号
/*
 * $Id: IdleThread.java,v 1.2 2003/12/25 09:19:03 epr Exp $
 */
package org.jnode.vm;

import org.jnode.system.BootLog;

/**
 * Thread that is run when the processor is idle.
 * 
 * @author Ewout Prangsma (epr@users.sourceforge.net)
 */
public class IdleThread extends Thread {

	private int counter = 0;

	public IdleThread() {
		super("idle");
		setPriority(Thread.MIN_PRIORITY);
	}

	public void run() {
		while (true) {
			try {
				counter++;
				if (counter == 1000) {
					counter = 0;
					//Screen.debug('*');
					testThreads();
				}
			} catch (Throwable ex) {
				BootLog.error("Error in idle thread", ex);
			}
			Unsafe.idle();
		}
	}

	/**
	 * Verify the state of all threads in the system.
	 */
	private final void testThreads() {
		ThreadGroup grp = getThreadGroup();
		while (grp.getParent() != null) {
			grp = grp.getParent();
		}
		final Thread[] threads = grp.allThreads();
		final int[] states = new int[VmThread.MAXSTATE+1];
		final int count = threads.length;
		//Screen.debug("#Threads " + count + "\n");
		for (int i = 0; i < count; i++) {
			final Thread t = threads[i];
			if (t != this) {
				states[t.getVmThread().getThreadState()]++;
				try {
					t.getVmThread().verifyState();

				} catch (Throwable ex) {
					BootLog.error("Error in thread " + t.getName(), ex);
				}
			}
		}
		/*for (int i = 0; i < states.length; i++) {
			Screen.debug(VmThread.STATE_NAMES[i] + "  " + states[i] + "\n");
		}
		Screen.debug("\n");*/
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?