How to work with multiple threads in a most effective and without synchronize in java?

ash das :

There is a bus booking site and around 100k threads are acting on it but total seats are only 20. How will you control the performance and what will be your approach in Java multithreading?

I replied that i will go for synchronize methods or block as it will control the concurrent threads and lock will prevent asynchronous execution.

But the interviewer interrupted me and said that syncronize is a bogus idea and performance will degrade and its not helpful.

Please let me know if i am missing any other useful multithreading concept that can fix this issue

Sambit :

You have to use Semaphore of permits 20, it means at a time 20 passengers can occupy seats if passengers are considered as thread. This may be answer only in case of core java multi threading.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=130126&siteId=1