Do you think singleton scope is a good idea in multithread environments, how do we maintain the synchronism if multiple threads are trying to modify the same single bean object?
Do you think using prototype scope is better in such a case or does having a single copy of the bean for each client makes it a dead tortoise speedwise?
I am especially interested in high throughput, ultra low latency trading applications where timed execution is of prime essence. Losing a minute (in creating a copy of the bean), could cause the trade to stale out and enter a dead queue, eventuall losing out on $$.
"Too many" is pretty vague: typical Java applications create and destroy tens, if not hundreds, of thousands of objects during normal execution.
Joined: Jul 05, 2005
Every single object uses memory. Amount of memory depends on number of objects multiply concurrent users.
If using some feature of application requires creating 10 objects, if there are 100 concurrent users, there will be 1000 objects created at a given time. But if the objects are singleton there will be only 10 objects regardless the number of concurrent users.
My recommendation is make services stateless if possible and use singleton scope.
Creating too many objects can cause full GC which is very bad for applications that response time is important, and the worst is OutOfMemoryError happens.
I don't think time used in creating objects will take up to a minute (even consider concurrent users), but if combine with full GC/repeately full GC, it's possible.