Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!

Ajay Saxena

Ranch Hand
+ Follow
since Nov 13, 2006
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ajay Saxena

Short answer : Through continued work and experience gained in the process

Long answer : Read on..

Step 1. Go through some of the common design patterns ,and try to build a general understanding of what kind of problems each pattern aims to solve. You could then probably take a look at the implementation (and the design docs,if any) of the product you are working on.Then try to identify the design patterns in the implementation. That would reinforce your understanding of the desing patterns ,in general.

Step 2. Start working on some problem by analysing it from different perspectives. Understand the performance and scalability requirements of the same,the kind of user load the solution could be exposed to,whether it would be wise to make the system concurrent etc.

Step 3. Test and see if your design meets the perf/scalability benchmarks

Step 4. Loop 1-3 till you get the appropriate design meeting the benchmarks.

In the process you would definitely develop design skills.

7 years ago

Dude what's google there for ?

Anyway, check out and the references provided there.

Ravi Kiran V wrote:Ok thanks , then what is the appropiate way to update the cache .

There's no correct answer.

The appropriate strategy depends on a lot of factors. You need to seek answers to the following(the list is not exhaustive though )

- What frequency does your data get updated
- What's the cost of object creation
- What's the size of the objects
- What frequency does the data get updated at
- Whether the application is clustered (multi-server)

Besides cache updation,you also need to think about a cache expiration strategy suitable to your application.

It could be a wise idea to do a detailed analysis of your application's requirements and design and then leverage the capabilities of the open source caches available in the development community,such as OS
cache,Memcached etc.

A discussion on different caching strategies could be found at

7 years ago

3)I dont know if this question is related to threads, i thought it might be achieved through threads,

If two persons at the same time are trying to buy ticket for the same seat in a Airplane? How to avoid this situation and not let the seat become blocked?

This is a problem of DB transactional concurrency control. It could be solved efficiently using optimistic concurrency control (by maintaining a version_id column in the DB table for Seats).
Doing it using in-memory synchronization would require synchronizing on some common object whenever the bookSeat() operation is invoked.
But that would have a huge performance impact as the bookSeat() would synchronize on the common object even when different seats are being booked.
Watch out for check-then-put pattern in your code which requires external synchronization.
e.g let's say we have the following piece of code

If the application is so designed that the method foo() could be invoked on the same object in multiple threads,it's not sufficient to just declare the map as a synchronized collection,as done in line # 02
Try reasoning out why.

pete reisinger wrote:
synchronized method is the same as synchronized block on "this":

That's correct as as long as you don't have any logic outside the synchronized block in the enclosing method.

Also,your requirement is not quite clear. Are you trying to synchronize access to the object returned by getSth()? Can you elaborate your requirement in detail.
May be you can share the source code and state your requirements.

I have a class (say class 'A' ) which has two methods [ m1() and m2() ] both are synchronised.
Is it possible to call m1() and m2() of the same object of class 'A', by two separate threadts 't1' and 't2' concurrently:

What do you mean by t1.m1() and t2.m2()?They don' seem to make sense. You are probably referring to a.m1() and a.m2(),where a is an object of class A,each being called from a separate thread (a.m1() in T1,and a.m2() in T2).

If above is the situation,only one of the threads T1 and T2 could be executing at a given point in time,simply because each of them would have to acquire a lock on a's monitor.
Try the "select for update nowait" semantic available on some DBMSes. Also, there's probably a way to configure a timeout on the plain "select fro update" clause.
How about using an interruptible channel of communication,available in the java.nio,in T1,and have it interrupted or asynchronously closed by T2?

Ofcourse there's no guarantee that the same conn object is reassigned to the same thread. However how could a single conn object be shared amongst multiple threads,if the connection pool doesn't explicitly allow that.If the pool does allow sharing of the same conn object across different threads,you definitely need to think about thread safety issues while invoking the socket APIs.

I am doing this because, watching the Socket class implementation, nor the status variable "connected" is not volatile, nor is setted in a synchronized block, so I thought that if 2 threads try to check the status of the socket, one could read a stale value of the "connected" boolean.

Are you having a single connection object shared by multiple threads in your Connection Pool implementation? If not,why do you care about the thread safety of the isConnected() method?
I guess you'd be better off letting us know your requirements in detail. Why would you even consider RMI/HTTP/FTP etc if you are not really building a client -server or peer-2-peer kind of application? I'd like to understand what motivated you to consider RMI in the first place.

8 years ago
Depends on the type of clients that would access the Java/J2EE equivalent of your CORBA service.

Some pointers..

1. If your client is going to be a pure java client,consider writing an RMI service

2. If you want to keep the service accessible to the existing CORBA clients,consider implementing the CORBA service using EJBs

3. For any generic client,consider exposing a Java based web service over SOAP

8 years ago
Also consider getting a copy of the book 'Distributed Systems ,Principles and Paradigms' by Tanenbaum for a rigorous academic introduction to the subject.
8 years ago

This exact functionality is already available -- see the java.util.concurrent.CountDownLatch class. Using this class, the 10th thread simply calls the await() method, while the other 9 calls the countdown() method (upon completion).

That would be good..You made me feel prehistoric Henry Looks like I really need to get my hands dirty with the java.util.concurrent classes... On a +ve note,getting down to the basics helps get the behind the scenes mechanics clear. That said,I again endorse the proposal for invoking the CountDownLatch APIs in this problem.