wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes To M Spritzler - Client Thread ID change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply locked New topic
Author

To M Spritzler - Client Thread ID change

Duane Riech
Ranch Hand

Joined: Feb 27, 2003
Posts: 52
Please help....
This is a followup to the "check client id" post..
The following is the log output when two clients are running network mode against the server. The
first client locks record 5, the second client
trys to lock the entire database. The log shows
that the first client is successful in locking record 5, the second client locks the first 4 records and waits on the 5th. Client 1 then releases the lock on record five, and the second client locks the remaining records in the database.
When the second client trys to unlock the records in the database, notice how the Thread ID changes,
so the lock logic doesn't think the second client owns the records previously locked.
The Thread for the second client starts out as
RMI TCP Connection(6)-127.0.0.1
then, after locking the database, CHANGES to
RMI TCP Connection(7)-127.0.0.1

so the unlock method will fail since it thinks it
is a different connection.
I tried storing/comparing on the Thread itself,
but got the same results.

Any comments.........

C:\Program Files\Java\Duane\Development Certification\Program>java RegFBNSDataba
se .\suncertify\db\db.db
FBNSDbRemote - ScheduleDb is <suncertify.db.Data@750159>
method lock() - Thread <RMI TCP Connection(4)-127.0.0.1> attempting lock
Attemping to lock record <5>
Lock on record <5 was successful for Thread <RMI TCP Connection(4)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(4)-127.0.0.1,5,RMI Runtime]

method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attempting to lock entire database.

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <0>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <0>
Lock on record <0 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <1>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <1>
Lock on record <1 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <2>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <2>
Lock on record <2 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <3>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <3>
Lock on record <3 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <4>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <4>
Lock on record <4 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(4)
-127.0.0.1,5,RMI Runtime]
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <5>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <5>
Lock() -- Lock on record <5> unavailable for Thread <RMI TCP Connection(6)-127.
0.0.1> waiting.......
method unlock() - Thread <RMI TCP Connection(4)-127.0.0.1> attempting unlock on
record <5>
Attempting to unlock record <5>

In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(4)
-127.0.0.1,5,RMI Runtime]
>
current Thread <Thread[RMI TCP Connection(4)-127.0.0.1,5,RMI Runtime]>
Thread owns lock...
Lock on record <5 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <6>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <6>
Lock on record <6 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <7>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <7>
Lock on record <7 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]
In ownsLock() object <LockStatus = false ThreadID = null
>
current Thread <Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]>
Database Lock - Locking record <8>
method lock() - Thread <RMI TCP Connection(6)-127.0.0.1> attempting lock
Attemping to lock record <8>
Lock on record <8 was successful for Thread <RMI TCP Connection(6)-127.0.0.1>Lo
ckStatus = true ThreadID = Thread[RMI TCP Connection(6)-127.0.0.1,5,RMI Runtime]

method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <0>
Attempting to unlock record <0>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <1>
Attempting to unlock record <1>

In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <2>
Attempting to unlock record <2>

In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <3>
Attempting to unlock record <3>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <4>
Attempting to unlock record <4>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <5>
Attempting to unlock record <5>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <6>
Attempting to unlock record <6>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <7>
Attempting to unlock record <7>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
method unlock() - Thread <RMI TCP Connection(7)-127.0.0.1> attempting unlock on
record <8>
Attempting to unlock record <8>
In ownsLock() object <LockStatus = true ThreadID = Thread[RMI TCP Connection(6)
-127.0.0.1,5,]
>
current Thread <Thread[RMI TCP Connection(7)-127.0.0.1,5,RMI Runtime]>
[ March 09, 2003: Message edited by: Max Habibi ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

When the second client trys to unlock the records in the database, notice how the Thread ID changes,
so the lock logic doesn't think the second client owns the records previously locked.

Mark is in North Dakota on vacation, but he is likely to close this thread when he returns because exactly same issue is discussed in this thread, where you also participated. As it has been pointed out by many people here, RMI runtime makes no guarantees with respect to mapping remote object invocations to threads. Because of this, you should consider an RMI Factory approach to identify the clients.
Eugene.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
As the other bartender here, I choose not to close this thread, because it sounds like Duane is specifically asking for Mark's help.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Java Regular Expressions
Duane Riech
Ranch Hand

Joined: Feb 27, 2003
Posts: 52
Your right, we're discussing this on another Thread. Please feel free to close this one.
Thanks for the response
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: To M Spritzler - Client Thread ID change