gutta rahul

Greenhorn
+ Follow
since Nov 23, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by gutta rahul

I would go with B, D and F due to following reasons.

1) Some other thread invokes the notify() method for this object and thread happens to be arbitrarily chosen as the thread to be awakened.
2) Some other thread invokes the notifyAll method for this object.
3) Some other thread interrupts thread T.
4) The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified.

from 1) we can't say the thread will be the same one which is in waiting state will be notified so answer A will go down.
Hi,

Iam new to transactions. If I begin a UserTransaction and begin the transaction using the begin() method given, will the subsequent calls to other methods after begin() and commit() will be tied implicitly to the transaction context? Thanks in advance.
class SyncTest {

private int x;

private int y;

private synchronized void setX(int i) {
x = i;
}

private synchronized void setY(int i) {
y = i;
}

public void setXY(int i, long sleep) {
setX(i);
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
setY(i);

}

public synchronized boolean check() {
return x != y;
}

}

public class ThreadTest extends Thread {
private SyncTest st = null;

private long sleep;

public ThreadTest(SyncTest st, long sleep) {
this.st = st;
this.sleep = sleep;
}

public void set(int i) {
st.setXY(i, sleep);
System.out.println(st.check() + " " + getName());
}

public void run() {
for (int i = 0; i < 10; i++) {
set(i);
}
}

/**
* @param args
*/
public static void main(String[] args) {
SyncTest st = new SyncTest();
ThreadTest tt = new ThreadTest(st, 1000);
ThreadTest tt1 = new ThreadTest(st, 500);
ThreadTest tt2 = new ThreadTest(st, 100);
tt.start();
tt1.start();
tt2.start();
}
}

This is what I ran and concluded for answer B
I tried to introduce sleep in between the two calls got setX and setY in the setXY() method to slow the process and it returned true. The lock on the object will be released after the completion of setX() method and then there is always a possiblity of another thread calling the check() method on the same object by acquiring the lock and return true. So the answer is B.
public class ThreadTest extends Thread {
private SyncTest st = null;

public ThreadTest(SyncTest st) {
this.st = st;
}

public void set(int i) {
st.setXY(i);
System.out.println(st.check() + " " + getName());
}

public void run() {
for (int i = 0; i < 10; i++) {
set(i);
}
}

/**
* @param args
*/
public static void main(String[] args) {
SyncTest st = new SyncTest();
ThreadTest tt = new ThreadTest(st);
ThreadTest tt1 = new ThreadTest(st);
ThreadTest tt2 = new ThreadTest(st);
tt.start();
tt1.start();
tt2.start();
}
}

I tried writting some code using the same object with different Threads of execution and got only "False" as the output. If Iam wrong can someone come up with a better reasoning.
We cannot call the abstract method in the immediate super class using super nor can use just super(). So in this case we cannot chain the finalize method from class C. super() alone should always be used as the first statement in the construtor but not in chaining the methods.
Hi,

in line 5 and 6 you are using \0061 instead of \u0061, which is giving the compilations error on those lines.
I agree with NareshAnkuskani reply.
In <? extends XXX>, "?" represents any type which is child of XXX. Suppose there are B, C and D child classes for base class A, then <? extends A> represents that any of the classes types B, C and D can be passed to "?" which is bounded by base class A.

Iam preparing for 1.5 certification and, if there is any worng in the above explination, please correct me.
In the first sample the reference "m" given is of type MathObj, which is resolved at compile time, which is static binding. In the second sample the reference "m" is of super type Math and is resolved at runtime, which is late binding.
Please check out Head First Design Patterns book by Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates.
15 years ago