Win a copy of Terraform in Action this week in the Cloud forum!

VuTuan Tran

Greenhorn
+ Follow
since Oct 21, 2010
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
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by VuTuan Tran

Thanks all for your answers. They do help much.
There is one left question about join() is when should we use join() and why should we use it
11 years ago

Henry Wong wrote:
In this case, by "current thread", I mean the thread that called the join() method... which is also the thread that created "fred" and "lucy".


So it is the main thread. isn't it
11 years ago

Henry Wong wrote:

VuTuan Tran wrote:
I think th2 is still alive because I did not invoke t2.join().I am not sure it is right or wrong.


Well, I'm afraid it's wrong. The join() method is used to cause the current thread to wait for the thread (represented by the thread object) to complete. It has no affect on the thread.
Henry


It is better now. However, there are 2 things I have to get through.Again from my OP, if i name these threads ( just for convenience )

At line 12, join() method is used to cause the current thread to wait for the thread to complete.
So, I know the thread,for sure, is gonna be "fred", but not sure about current thread and complete
Can you tell me which one is the current thread and what do you mean complete here
11 years ago

Henry Wong wrote:
Why wouldn't th2 finishing before the main thread checks up on it, be an option?
Henry


I think th2 is still alive because I did not invoke t2.join().I am not sure it is right or wrong.
11 years ago
Codes are given from this and I did add some lines of code to know how I understand about the join() method



After running the file, the result is

And then I run the file one more time, the result is total different from the first one

Both of the results are not what I expect and What I am expecting is th2 is still alive


I need some help to make it clear please.Thanks
11 years ago

Nipun Arora wrote:

VuTuan Tran wrote: .... Question 2 : At line 4, after t1.start(), which thread will execute first ....


The main thread will execute first, and if you ask which thread will complete execution first, then its t1 since t1.join causes main to wait for t1 finish execution..

VuTuan Tran wrote: .... Question 3 :what t1.join() does ? ....


t1.join() interrupts main() from being runnable and main waits for t1 to complete its execution ..


I doubt main thread will execute first. There is another issue I should make it clear is

Given the preceding code from OP, what our current thread is
11 years ago
Given from scjp


There are some questions which i made up myself to test how i understand about the thread issue and I really need some experts to confirm about it.

Question 1 :At line 3, how many threads we have now ?
my answer is

Question 2 : At line 4, after t1.start(), which thread will be execute first.
My answer is
Question 3 :what t1.join() does ?
my answer is
What I am thinking is t.join() joins the current thread to the end of t so that when t finishes the current thread can run again. However, which one is the current thread now. That is why I am stuck
Please help me. I appreciate
11 years ago

1.import java.util.*;
2.public class CreateAnArrayList {
3.public <T> void makeArrayList(T t) { // take an object of an unknown type and use a "T" to represent the type
6.List<T> list = new ArrayList<T>(); // now we can create the list using "T"
8.ist.add(t);
9.}
10.}


At line 3. what is the meaning of this public <T> void.I am confusing because unknown type T goes with void in this case.Usually, void is return nothing.
Please help me,thanks
11 years ago

Christophe Verré wrote:There's only one parameter : live2. So only args[0] is valid.


Ahhhhhhh, it is my bad. Thanks for pointing out.
11 years ago
This question is taken from SCJP 6 study guide

1.class Fork {
2.public static void main(String[] args) {
3.if(args.length == 1 | args[1].equals("test")) {
4.System.out.println("test case");
5.} else {
6.System.out.println("production " + args[0]);
7.}
8.}
9.}
And the command-line invocation:
java Fork live2
Question : what is the result


I dont understand why the answer is

E. An exception is thrown at runtime


My logic is :at line 3 we are going to have
It is equivalent to
I know my logic is wrong but I cant figure it out. Please help me to make it clear.Thanks
11 years ago
There are 2 classes and one is subclass of another like below:



The first one is correct one but the second. I do not have a good explanation for that. I do know that

A reference variable can refer to any object of its declared type or any subtype of its declared type


and why not

A reference variable can refer to any object of its declared type or any supertype of its declared type


Im not convinced myself. Please help, thanks
11 years ago

Abimaran Kugathasan wrote:

VuTuan Tran wrote:My question is 2 but the rite one is 1. I dont quite get it. I need some help,please


UseRealWords here, and, the object which is referred by a1 will be eligible for GC, but, not it's instance object a1.b2.



Sorry about that because I am new member.
Back to posted question,can you tell me more details about it.Thanks

Deepak Bala wrote:Welcome to JR VuTuan

Please QuoteYourSources


I am sorry about that. I will do that for the next thread.
Given

Question is

My question is 2 but the rite one is 1. I dont quite get it. I need some help,please