Help coderanch get a
new server
by contributing to the fundraiser

Patrick Wang

Greenhorn
+ Follow
since Oct 15, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Patrick Wang

Hi:
I want to know if there is a free java message queue software which I can make use of?
Thanks
pat
Hi,
First I want to thanks this forum provide a lot of useful information for the 4 weeks laid off time. Fortunately I landed a job as a programmar analyst. Now I am doing some internal application for my boss. First I need to choose tools, J2EE versus Microsoft .NET/COM. I lean towards Java but everything here they are using are ASP, SQL Server. Also I need to some integration work between my application and existing one. So my boss asked me to provide a decent proposal that J2EE actually outweigh the Microsoft, since my boss is not really into technical field, so I cannot get into too techie on this. I try to give her a non-tehie, but very detailed comparasion between the .NET/COM versus J2EE, anybody has any useful insight?
Thx
Pat
22 years ago
I have about the same experience with you.
Drove 100 miles to Sacrementa for an interview, get called on
Monday asking if I can interview tomorrow. Then no answer...
The recruiter company is APPLEONE if I am not mistaken.
You are not alone.

22 years ago
I have been given a test question as below, I think the answer is 5), but not sure about this. Can somebody shed some light on this?
Thx
Pat
===============================================================
public class Foo
{
public void doIt( Field myField )
{
???
}
}
Given the above code, what code do you add to the doIt() method to find out whether myField is static?
Choice 1
if ( myField.isStatic() )
Choice 2
if ( myField.getModifier().isStatic() )
Choice 3
if ( Modifier.isStatic( myField.getModifiers() ) )
Choice 4
if ( myField.getModifiers() == Field.STATIC )
Choice 5
A Field object CANNOT represent a static field.
22 years ago
Hi Kyle:
Here is another puzzle. Do you have any input?
Which one of the following reduces resource overhead in order to improve performance?
Choice 1
Limiting the number of bean methods per bean, which increases the number of beans
Choice 2
Increasing the number of bean methods per bean, which decreases the number of beans
Choice 3
Establishing JDBC connections early in bean execution
Choice 4
Increasing the passivation timeout value
Choice 5
Increasing the session timeout variable
Thx
Pat
Only one choice is correct(radio button), I am confused too. I think this is some propertary test.
Thx
Pat
Thx Kyle for clarifying this.
Here is another puzzle.
What types of entity beans support multiple finder methods?
Choice 1
Activated entity beans
Choice 2
Stateful session beans
Choice 3
BMP entity beans
Choice 4
CMP entity beans
Choice 5
Passivated entity beans
I think the answer should be activated Entity Bean's, is this correct?
Thx
Pat
Yes, it is a test. Thx for clarifying this.
Here is another puzzle
Which one of the following is a good design principle for stateful session beans?
Choice 1
Pass client data with each method call to ease the container burden
Choice 2
Use only when thread creation is necessary
Choice 3
Use fewer, larger method calls
Choice 4
Do not use for persisting data
Choice 5
Use synchronized methods within the bean

I think either 3 or 4 is correct, but you can only select one
correct answer. So I select 4.
Thx
Do I only need
1) Remote Interface
2) Bean Implementation
3) EJB jar
4) EJB jar with manifest
I think 3) is correct, is that true?
Because in RMI world you only need the bean implementation in order to produce the proxy stub, (which already include the remote interface and bean implementaion)
Thx
Pat
Gennady:
Remote Connection is distinct for each client, as long as thread
is distinct for each client which is true, I think by using thread is another approach. Thx for giving the two level lcoks
design, it is beautiful.
Thx
Pat
Recently I got an interview question like this:
Please describe conceptually what an application life cycle looks like.
My answer is:
1) Gather user��s requirement 2) Explore, analysis and design system architecture, select tools. 3) Software Architecture Design. 4) Finish coding 5) Unit Testing and performance tuning 6) Support customer.

Apprently it is not good enough, can somebody cast some light on
how to detailize the answer.
Thx
Pat
22 years ago
Here is the source for the single layered lock.
This is what I hacked through, getDatabaseLock need to get the
curDatabaseLock object, while getLock synchronized based on
this. I use "this" object to guard the access to the hashMap locks and the rest variables.
It is not as nice as the two level locks presented above.
Thx.
B.T.W, I changed the lock signature on the server side, where
on client, it is still the old lock signature.
-----------------------------------------------------
package com.hachi.server.lock;
import com.hachi.server.connect.*;
import java.util.*;
public class LockManager {
public static int DATABASE_LOCK_RECORD = -1;
int waitForDatabaseLock = 0;
RemoteConnection curDatabaseLock = null;
HashMap locks;
ArrayList waitingForDatabaseLock = new ArrayList();
public LockManager() {
locks = new HashMap(); // key record number, value client sessionID
}

void getDatabaseLock(RemoteConnection sessionID) throws InterruptedException {
synchronized (this) {
waitForDatabaseLock++;
if (locks.isEmpty() && (curDatabaseLock ==null)) {
waitForDatabaseLock--;
curDatabaseLock = sessionID;
return;
}
waitingForDatabaseLock.add((RemoteConnectionImpl) sessionID);
}
synchronized (curDatabaseLock) {
while ( !sessionID.equals(curDatabaseLock)) {
wait();
}
}
synchronized (this) {
waitForDatabaseLock--;
int i = waitingForDatabaseLock.indexOf(sessionID);
waitingForDatabaseLock.remove(i);
}
}
void getLock(int recNum, RemoteConnection sessionID) throws InterruptedException {
Integer rec = new Integer(recNum);
if (recNum == DATABASE_LOCK_RECORD) {
getDatabaseLock(sessionID);
return;
}
synchronized (this) {
if ((curDatabaseLock ==null) && (locks.get(rec)==null)) {
locks.put(rec, (RemoteConnectionImpl) sessionID);
return;
}
while ( curDatabaseLock !=null | | locks.get(rec)!=null) {
wait(); //database lock has priority over row lock, so there must be no database lock.
}
locks.put(rec, (RemoteConnectionImpl) sessionID);
}
}
synchronized public void unLock(int recNum, RemoteConnection sessionID) {
// release DatabaseLock
if (curDatabaseLock !=null ) {//only database lock held, no row locked, only need to release database lock
if ((recNum != DATABASE_LOCK_RECORD) | | (!curDatabaseLock.equals(sessionID)) )
return;
if (waitForDatabaseLock > 0) {
curDatabaseLock = (RemoteConnection) waitingForDatabaseLock.get(0); // ANY_SESSION_LOCK is used to block the row lock.
synchronized (curDatabaseLock) {
// notify database lock
curDatabaseLock.notifyAll();
}
return;
}
else {
curDatabaseLock = null;
// notify row lock()
notifyAll();
}
}
// release row lock;
if (recNum == DATABASE_LOCK_RECORD) return;
Integer rec = new Integer(recNum);
RemoteConnection lockSession = (RemoteConnection) locks.get(rec);
if (lockSession.equals(sessionID)) {
locks.remove(rec);
if (locks.isEmpty() && waitForDatabaseLock > 0) {
RemoteConnection databaseSession = (RemoteConnection) waitingForDatabaseLock.get(0);
curDatabaseLock = databaseSession;
synchronized (curDatabaseLock) {
curDatabaseLock.notifyAll();
}
}
else {
curDatabaseLock = null;
notifyAll();
}
}
}

}
Hi,
I am confused about the RMI UnicastRemoteObject,
I know a client can look up a server which create a object whose class extends remote, the object then casted to a remote interface and passed back to the client, then client was able to manipulate the remote interface.
Why there is a need to let the object's class extends
UnicastRemoteObject, without extending the UnicastRemoteObject, it seems to work anyway.
public class A implements IA(RemoteInterface)
{extends UnitcastRemoteObject} *******What do we gain by adding this line.
Server B {
main() {
x= new A();
return (IA) x;
}
}

Thx
Pat
22 years ago
Thx Peter,
I found the two level synchronized is not necessary,
just use synchronize(this) to synchronize both the primitive
member and locks object. In that way the design will be
much cleaner.
Pat
Because there are two levels of lock, databaseLock and rowLock.
F.g. a database lock may either locked by another database lock, or by a row lock.
Database Lock is checked through the curDatabaseLock variable value, so need to synchronize access to it using this lock.
Row lock check is checked through the locks hashmap, so need to synchronize on it.
Another reason is row lock is waited against locks hashmap object, while database lock is waited against this object.
Thx
Pat