代码如下
public class SyncThread implements Runnable {
public static void main(String[] args) {
System.out.println(“this is”+ count);
}
private static int count;
public SyncThread() {
count = 0;
}
public void run() {
synchronized (this) {
for (int i = 0; i < 5; i++) {
try {
System.out.println(Thread.currentThread().getName() + “:”
+ (count++));
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public int getCount() {
return count;
}
}
是在myeclips中写的,运行后就报 错误: 找不到或无法加载主类 newa.SyncThread。不是环境变量的问题,是和debug和release调试方法有关吗,小弟对这两种调试方法不是很懂,望各位解惑。
public class SyncThread implements Runnable {
public static void main(String[] args) {
System.out.println(“this is”+ count);
}
private static int count;
public SyncThread() {
count = 0;
}
public void run() {
synchronized (this) {
for (int i = 0; i < 5; i++) {
try {
System.out.println(Thread.currentThread().getName() + “:”
+ (count++));
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public int getCount() {
return count;
}
}
是在myeclips中写的,运行后就报 错误: 找不到或无法加载主类 newa.SyncThread。不是环境变量的问题,是和debug和release调试方法有关吗,小弟对这两种调试方法不是很懂,望各位解惑。
解决方案
20
朋友你的main方法放外面吧,然后调用线程
public class SyncThread implements Runnable { private static int count; public SyncThread() { count = 0; } public void run() { synchronized (this) { for (int i = 0; i < 5; i++) { try { System.out.println(Thread.currentThread().getName() + ":" + (count++)); Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } } public int getCount() { return count; } } class test { public static void main(String[] args) { SyncThread s = new SyncThread(); s.run(); } }