Home > Back-end > Zhang SAN has two competent employees, competent A and B are often zhang SAN's wages, according
Zhang SAN has two competent employees, competent A and B are often zhang SAN's wages, according
Time:10-17
CodePudding user response:
Adjustment (A, zhang) as long as using this method in the implementation of the lock, zhang work went,
CodePudding user response:
The following provides a reference
Public class Person { public String name; Public double salary; Public int your; Public Person (String name, double salary, int your) { super(); this.name=name; This. Salary=salary; This. Your=your; } Public double getSalary () { return salary; } Public void setSalary (double salary) { This. Salary=salary; }
Public int getAchieve () { Return your; } Public void setAchieve (int your) { This. Your=your; } Public Boolean achievement () { If (achieve> 100) return true; The else return false; } }
Public class Adjust implements Runnable { Person p=null;
Public Adjust (Person) p { super(); This. P=p; }
Public synchronized void the run () { While (true) { If (p.a chievement ()) { P. etSalary (p.g etSalary () + 1000); P. etAchieve (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 (); }