Originally posted by Ashok Pradhan:
Can someone explain me the Exercise 9-2 page 710 on K&B book from step 3,4,5,6.
How to increase the character within the string buffer.
because .net guys can also write in java
Thanks<br />Dinesh
2 Override the run() method of Thread. This is where the synchronized block of code will go.
because .net guys can also write in java
Because the identifier for the object differs only by S/s from the name of a class.Originally posted by Noam Wolf:
@Campbell - why is it not a good identifier?
Rajeev Kumar
SCJP 6.0 Certified 96%
Originally posted by Rajiv Chopra:
I just solved the problem. Please let me know if anything wrong!!
public class ClassOne extends Thread {
private StringBuffer sb;
public ClassOne(StringBuffer sbx) {
sb = sbx;
}
public void run() {
synchronized (this.sb) {
ClassOne co1 = new ClassOne(sb);
co1.printmethod();
}
}
public void printmethod() {
System.out.println("Thread :" + sb);
for (int i = 0; i < 100; i++) {
System.out.println(sb);
}
char c = this.sb.charAt(0);
this.sb.setCharAt(0, ++c);
}
public static void main(String[] sr) {
StringBuffer sb1 = new StringBuffer("A");
ClassOne cs1 = new ClassOne(sb1);
ClassOne cs2 = new ClassOne(sb1);
ClassOne cs3 = new ClassOne(sb1);
cs1.start();
cs2.start();
cs3.start();
}
}
[ December 19, 2008: Message edited by: Rajiv Chopra ]
Rajeev Kumar
SCJP 6.0 Certified 96%
Consider Paul's rocket mass heater. |