Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!

David Hadiprijanto

Ranch Hand
+ Follow
since Sep 14, 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 David Hadiprijanto

I am quite new in encryption. Are different implementations of Blowfish are supposed to be compatible with each other? For example, if I use a Blowfish.J to encrypt, can I decrypt it using another like Blowfish by Chilkat (www.chilkatsoft.com) (Delphi platform).

I have a project where I need to encrypt and decrypt using two different software on two different platform. So far, I tried different implementation of Blowfish and they are not compatible with each other (using the same key).

- david
15 years ago
I like the way Mark put it. There is a spectrum between the manager doing all the evaluation and the worker doing all the evaluation. Ideally, there will be a balance - so something in the middle.

However, regardless where it is in the spectrum, I think what is more important is whether the evaluation really work. Does the evaluation protocol/method indeed makes better employees in the future/long run?
One key will be the commitment of the manager (most importantly the executive managament, those on the top), to value their employees as one of their most important asset. Another is that they are competent managers/executives. If this is so, I don't really care where it is in the spectrum. I will follow their leadership and learn from them.

- david
15 years ago
Hello Sergei,
Let's try walk it thru.
  • 1. The program starts at the static main method of class ThreadA - line 2.
  • 2. It creates a ThreadB object and then start its own thread by calling b.start() - line 4.
  • 3. At this point we have two thread running concurrently, for simplicity let's call them thread A (started from static main method) and thread B (started from b.start - line 4).
  • 4. thread A will continue to line 6, and thread B will start executing the run() method - line 19. Both thread is about to synchronize on the same object - b. Let's say, thread A gets a hold on the b's lock first, so it will continue on line 7 while thread B will be blocked at line 20.
  • 5. So, thread A will execute line 8. Then, (and here is your question), it calls b.wait(). What does it mean? It means thread A will be put in b's waiting list and will be blocked (stop running), until a call to b.notify() (or b.notifyAll()) is made and thread A is picked to be removed from b's waiting list.
  • 6. So, now thread A is being blocked, and it releases the b's lock (wait() causes the object's lock to be released). As a result, thread B, now picks up the lock and continue on line 21 thru 23. At line 24, thread B calls b.notify(), what it does is it removed one thread from b's waiting list (in this case, there is only one thread, thread A), and thread A will become runnable again. To be precise, at line 24, thread B is still holding the lock on object b, so, thread A still can not run. After line 25 - end of synchronized block - the lock on object b is released, and thread A is now able to pick up the lock and continue on line 10.


  • Now, as an exercise, what would happen if at point 4 above, instead of thread A that gets the lock, thread B gets the lock first? (meaning thread A will have to be blocked at line 6 and thread B will continue at line 21)
    Hope this helps.
    [ March 16, 2004: Message edited by: David Hadiprijanto ]
    This is a short one, but helped me to avoid falling into trick question :
    It's MINC not MIC : Map Is Not a Collection.
    Hi Dave,


    There are also four additional objects created in lines 3 & 4 of m1() that also become eligible for garbage collection.


    There are no more objects created in lines 3 & 4 of m1(). Perhaps, you mean there are four other references made to the four objects in lines 3 & 4 of m1()?


    Even though the references to those objects (the ones created in lines 3 & 4) never go away, they become eligible because the references to the objects they are contained in go away, so no existing thread has access to them. Is this correct, or am I off here?


    The keyword here, no live thread has access to them. So, you are correct that even though there are still references to the four objects other than i1, i2, i3, and i4, (as a result of lines 3 & 4 of m1()), but because they merely points to each other/itself, and no other live thread can access them, they become eligible for GC.
    Hope this helps.
    [ February 20, 2004: Message edited by: David Hadiprijanto ]
    Harvinder,


    1)I want to know those instances of the class that are eligible for the garbage collection (mine answer is all the four).


    I think you answered correctly.
    The four objects created in the first two lines of method m1() are all eligible for the garbage collection after method m1 returns, because only m1's local variables: i1, i2, i3, i4 refer to those four objects. After method m1 returns, those local variables goes out of scope and no more references to the four objects, so they are all eligible for GC.
    Hi Dave,
    I don't think answer A needs to be ammended by "lock on object B is released".
    Here is why I think so :
    [1] A calls wait(2000) on object B. A is therefore now in B's waiting list (blocked).
    [2] After 2 seconds or A is notified, A is moved back to Runnable state (will be a candidate to get another turn at the CPU).
    [3] A is picked by the Thread scheduler to run. Since it is still running in the synchronized context of object B, it will need object B's lock. So, if the object B's lock is being used by other thread (not released yet), Thread A will be blocked again.
    In another words, for thread A to move back to Runnable state from Waiting state as a result of calls to wait(2000) on object B, it only needs 2 seconds or being notified.
    Now, your comments :


    Once thread A is notified isn't it possible for thread A to be blocked on B's lock for a short period of time until the synchronized code in B is finished executing. What am I missing here?


    Yes, this will be at point [3] above, but beforehand, at point [2] thread A is already back in Runnable state - it just got 'unlucky' to be thrown to Blocking state again .
    Does it make sense?
    Sean,


    Please distinguish between the two calls, especially in the situation I have described above - unless, of course, the situation I described assumes something that is not correct.


    notify() will cause only one object in the waiting list of the corresponding object to be notified and be put back on Runnable state. Which one? No guarantee.
    notifyAll() will cause all objects in the waiting list of the corresponding object to be notified and be put back on Runnable state.
    So, in your situation above (writer and reader):
    1. If you use notify() on the writer, only one of the reader threads (JVM decide which one) will be made Runnable. Obviously, this is not desired in this situation.
    2. If you use notifyAll() on the writer, all the reader threads will be made Runnable - and all of them will then fight for the lock again so only one thread will be running in the synchronized block.
    So, which one to use? I think if you are dealing with multiple objects waiting on the same object, usually you want to use notifyAll().
    I hope this helps you to make the distinction between notify() and notifyAll(). They are quite simple, I think, really .
    [ February 19, 2004: Message edited by: David Hadiprijanto ]
    Hi Sean,


    But what then? As I have read, all of the waiting threads become 'runnable' which mean that they may be active within the synchronized block at the same time.


    The waiting threads will not be active/run within the synchronized block at the same time. When the waiting threads become Runnable, it is simply sitting on the Runnable pool, waiting to be picked by the Thread scheduler to run. Which one will be picked to run first? No guarantee. So, the first of those threads that get picked by Thread scheduler to run first will re-obtain the lock, and the other threads (which are also synchronized with the same lock) will have to wait until this thread releases the lock before each of them can be back running in the synchronized block.
    Does it make sense?
    [ February 17, 2004: Message edited by: David Hadiprijanto ]
    Hello Gayatri,
    at case 3 (when k=3, i=2, j=1), it breaks on label2, which like you said is the do-while. It then goes to the next statement to be executed after the do-while, (line 3 - the closing bracket for the for-loop) which tells it should execute the next iteration of the for-loop (line 1). Hence, i is now 3, and you get k = 3 + 1 = 4, and case 4 is executed.
    If you execute the code below, you will get :
    ...
    Inside do-while. i=2 j=1 k=3
    Beginning of for loop, i is incremented to : 3.
    ...
    It shows that after case 3: break label2; it goes back up to the beginning
    of the for loop, and i becomes 3.
    Hope this helps.
    Hello,
    I shared the same challenge as the others above.
    I work full time and no Java used in my work place.
    Dennis' said it quite bluntly but I share similar situation, after looking at computer screen and code all day long, the last thing I want to do after going home is to look at computer screen and code again.
    Add to that if you have to commute, and/or have family, studying may be the last thing in your mind after work.
    Having said that, I rarely spent too much time studying after work.
    I probably can read (concept) a little, but not practicing (writing code).
    If you can, study regularly, not just once a week (like on weekends).
    If you are a morning person, then wake up a little earlier and study.
    If you are not, then you can use lunch hour (like I did).
    I did not study every weekend and I did not study everyday also, but exposing myself with exam materials at least 2 or 3 days during the weekday, regularly, help me to remember more.
    I bought the K&B book in April last year, and I slowly finished it around late October. Around September I started with the mock exams. I used K&B (2 of them), Dan Chisholm (the best that I know of), and Marcus Greene (very good also). So the schedule was pretty relax to me (who wants to study during Summer where I live, here in the Northwest, US?), but I was getting there. A month approaching the exam date, the studying gets more intensive though, probably 2 hours every weekend and everyday during lunch hour. I took the exam in late December.
    One more thing, take it easy. Learn to relax while you are going through
    the mock exam. You will probably need them the most during the exam.
    Hope this helps.
    Congratulation. That is an impressive score.
    About the CertManager, according to Sun Website, usually it takes up to 4 days before the exam results will be available in the CertManager database.
    In my case, it took about 2 weeks before I can view the exam result in CertManager. But I took the exam on Dec 23, so there were Christmas and New Year holiday.
    16 years ago
    Hello Yosi,
    Congratulations. That is a very good score, especially with all the distractions. Your family must be very happy too, especially the kids, since now daddy will be able to join their running, screaming, and playing.
    16 years ago
    Hello Suriya,
    this issue has been discussed here.
    Hope you find the answer there.
    You need to synchronize on the object you were invoking notify() on.
    Otherwise you get an exception.
    See sample code below, Thread2 notifyThread1() has synchronized block using the th object, on which it invoke the notify() method.
    This sample code compiles and runs fine.
    The output, as expected :
    Thread1 Waiting...
    Thread2 Notifying Thread1...
    Thread1 Notified...