java thread.sleep() do not make processor time available to the other threads when I test

When I do work with Thread.sleep(),I found when current thread invoking sleep() method,other threads could not obtain the processor time to invoke their own.But I get the sleep() method's information from Oracle's doc conversely,so I'm confused.

Here is my code:

class ThreadTest {

private Runnable mRunnable = () -> {

println("from runnable start run");

println("from runnable start end");

};

private class TestThread extends Thread {

@Override

public void run() {

super.run();

println("from Thread start run");

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

println("from Thread end");

}

}

private void println(String info) {

System.out.println(getDate() + " : "+info);

}

private String getDate() {

SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间

sdf.applyPattern("yyyy-MM-dd HH:mm:ss a");// a为am/pm的标记

Date...

Read More »

By: StackOverFlow - 5 days ago

Related Posts