adjustment(A,zhang) 只要在执行这个方法的使用锁住,zhang的工作就行了。
解决方案 »
- JAVA使用没用的代理IP但能连接网络,这是啥问题呀!
- 求助:JAVA中一个类的代码长度长点好么?还是将一个长的类分成几个类好一点?
- 要在C/S系统中实现报表格式的任意定制,请问应该使用什么报表啊?
- 请帮我看看怎么进行优化?
- 学习JAVA的好地方(群号23539326)
- 大家有无试过去见工, 老板给你的工资只是要求的70% ?
- 怎么在JDialog设置addKeyListener(new KeyAdapter(){...})没有反应?
- 各位java精英们。请教个问题。【反射机制】
- 何处有JBuilder的学习资料?
- jdk8 不在使用odbc桥后 要怎么连数据库
- ⑧懂就问
- jdk 1.7 排序问题 Collections.sort(list, new Comparator<Integer>()
public String name;
public double salary;
public int achieve;
public Person(String name, double salary,int achieve) {
super();
this.name = name;
this.salary = salary;
this.achieve=achieve;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public int getAchieve() {
return achieve;
}
public void setAchieve(int achieve) {
this.achieve = achieve;
}
public boolean achievement() {
if(achieve>100) return true;
else return false;
}
}
public class Adjust implements Runnable {
Person p = null; public Adjust(Person p) {
super();
this.p = p;
} public synchronized void run() {
while (true) {
if (p.achievement()) {
p.setSalary(p.getSalary() + 1000);
p.setAchieve(0);
} }
}
}
public class test { public static void main(String[] args) {
// TODO Auto-generated method stub
Person p=new Person("zhangsan", 10000, 150);
Adjust A=new Adjust(p);
Adjust B=new Adjust(p);
Thread tA=new Thread(A);
Thread tB=new Thread(B);
tA.start();
tB.start();
}}