问题描述 : -
第1步:在主线程中从用户处输入FILE_NAME.
步骤2: 对该文件执行10次操作(即计数字符,计数行等),所有这10个操作必须在隔离线程中.这意味着必须有10个子线程.
第3步:主线程等待所有子线程完成.
第4步:打印结果.
我做了什么 :-
我做了3个线程的示例代码.我不希望你身边的文件操作代码.
public class ThreadTest {
// This is object to synchronize on.
private static final Object waitObject = ThreadTest.class;
// Your boolean.
private static boolean boolValue = false;
public final Result result = new Result();
public static void main(String[] args) {
final ThreadTest mytest = new ThreadTest();
System.out.println("main started");
new Thread(new Runnable() {
public void run() {
System.out.println("Inside thread");
//Int initialiser
new Thread(new Runnable() {
public …Run Code Online (Sandbox Code Playgroud)