Win a copy of Modern frontends with htmx this week in the Spring forum!

Arnab Karmakar

Greenhorn
+ Follow
since Jun 21, 2007
Merit badge: grant badges
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 Arnab Karmakar

Henry Wong wrote:

Arnab Karmakar wrote:
What if there are 5 thread and 5 connections in the pool. How can it be ensured that all gets access to an instance from the pool. If I make the getConnection() method synchronized, while thread 1 is trying to get a connection from pool (using getConnection() method), other threads will be waiting till Thread 1 finishes getting a connection. How can it be ensure that none waits for others?



The time to get a lock is quick, measured in nano seconds. This is probably true to get the connection from the pool (assuming that it has been preallocated). So it is not an issue. It is highly unlikely that anyone will notice that a thread had to wait its turn to get a connection -- especially since after the connection is gotten, the thread will be doing a network / I/O bound operation to a database.

Henry


You are considering the term "wait" as tolerance for a particular application. In some application 1 second might not be called as acceptable wait and in others 1 nano second might be called as too late. My question is, is it at all possible to provide Connection object from pool to the 5 threads at the same time without each thread waiting for others to get the object. That is to say, is it possible to do a lock free atomic operation.
Thanks to all.
13 years ago

Ireneusz Kordal wrote:No, it is not possible.
If you have 5 cars and 10 drivers, then only 5 drivers can drive a car, the other drivers must wait.
The same is true for 5 connections and 10 threads.



What if there are 5 thread and 5 connections in the pool. How can it be ensured that all gets access to an instance from the pool. If I make the getConnection() method synchronized, while thread 1 is trying to get a connection from pool (using getConnection() method), other threads will be waiting till Thread 1 finishes getting a connection. How can it be ensure that none waits for others?
If there are 10 threads who are trying to access connection object from database connection pool (5 instances in pool), how can it be implemented to ensure that none of the threads wait for any other thread to get a connection pool object.

I am not sure if it is at possible to ensure that all threads get access to connection object at the same time because there are only 5 instances in the pool (and 10 thread trying to access it).

Any insight will be appreciated.

Suhas Wadadekar wrote:Hi,

I understand that if there are more than one <auth-constraint> in the DD, the following happens:

1. If there is an empty <auth-constraint/>, then it overrides other <auth-constraint/>, then it denies access to all
2. If there is no <auth-constraint> or an <auth-constraint> with a role name *, then it grants access to all


But what happens if case 1 and case 2 coexist? Who wins?

Suhas.



it denies access to all
Hi Everybody,

After a long gap, I managed to appear for SCWCD. Got 98%, but not very happy as I was targeting 100%. I feel that 98% is very common and easy to achieve

Preparation : HFSJ and all free mock exams from internet.

Best of luck to all SCWCD aspirants.
13 years ago
Hi All,

According to spec (for SingleThreadModel)

"Ensures that servlets handle only one request at a time. This interface has no methods. If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet"

I have a question on
"or by maintaining a pool of servlet instances and dispatching each new request to a free servlet"

Suppose I have a servlet which does the following (servlet implemented SingleThreadModel)


If container is maintaining pool of instances and the container assigns separate request to separate available instances from the pool, how can the above code thread safe?

Thanks
Arnab
Can you please provide the email address you want to get the information?

Thanks
Arnab
16 years ago
Hi All,

I have cleared SCJP 1.4 with 100% today 21t June 2007. It was really cool. I was stuck up at one question which I luckily corrected while revising.

This group was a major help while preparing for the exam.

Now heading towards SCBCD.

Thanks
Arnab
16 years ago