GetPriority.java
资源名称:Source.rar [点击查看]
上传用户:songled
上传日期:2022-07-14
资源大小:94k
文件大小:1k
源码类别:
进程与线程
开发平台:
Java
- public class GetPriority extends Object {
- private static Runnable makeRunnable() {
- Runnable r = new Runnable() {
- public void run() {
- for ( int i = 0; i < 5; i++ ) {
- Thread t = Thread.currentThread();
- System.out.println(
- "in run() - priority=" +
- t.getPriority() +
- ", name=" + t.getName());
- try {
- Thread.sleep(2000);
- } catch ( InterruptedException x ) {
- // ignore
- }
- }
- }
- };
- return r;
- }
- public static void main(String[] args) {
- System.out.println(
- "in main() - Thread.currentThread().getPriority()=" +
- Thread.currentThread().getPriority());
- System.out.println(
- "in main() - Thread.currentThread().getName()=" +
- Thread.currentThread().getName());
- Thread threadA = new Thread(makeRunnable(), "threadA");
- threadA.start();
- try { Thread.sleep(3000); }
- catch ( InterruptedException x ) { }
- System.out.println("in main() - threadA.getPriority()=" +
- threadA.getPriority());
- }
- }