package com.wallta.thread;
public class MyObject {
public MyObject() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
MyObject myObject = new MyObject();
ThreadA a = new MyObject().new ThreadA(myObject);
ThreadB b = new MyObject().new ThreadB(myObject);
a.setName("A");
b.setName("B");
a.start();
b.start();
}
// 多线程 启用一个方法,使用关键字 synchronized 是的方法 同步,避免线程安全的问题.
public synchronized void methodA()
{
System.out.println("begin methodA threadName =" + Thread.currentThread().getName());
try
{
Thread.sleep(3000);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载