Thread concurrency - spin lock question

Hi everyone,
I want to enforce some concurrency in my code so that only 5 threads are running at a time. This is quite easy to do, but I just want to know if it would be more efficent to have a spin lock like this:
while( nActiveThreads >= 5 ){ }
or have some kind of sleep method in the loop so that it's not continually spinning in the loop and only checks every 50 milliseconds.
while( nActiveThreads > 5 ) {
try {
Thread.sleep(50);
} catch (Exception e) {
Any thoughts?
BBB

I recommend looking at the java.util.concurrent package, specifically at Executors and ExecutorService classes. You can choose from several different types of thread scheduler, telling them how many threads you with them to use.

Similar Messages

  • Thread waits and locks using Solaris 8 T1 threads

    Hi,
    I have got a problem relating to Webmethods running on JVM Hot Spot server VM (1.4.2_07-b05 mixed mode).
    From time to time the webmethods applications seems to slow down and completely lock up with the mpstat on solaris showing:
    1. context switching increases (csw)
    2. spin on mutexes also show approximately 25 % increase (smtx)
    The only way i could overcome this problem is to kill the process - which incidentally produces a thread dump. Incidentally i have also done a pstack on the process.
    The thread dump shows among other things alots of object waits, with locks on objects in an object Pool. The main process is in a waiting state on object, locked by itself, similarly other thread deamon are also in a waiting state on objects which itself has locked. Seems rather wierd (dont understand that).
    Anyway we are on Solaris 8 -using the T1 solaris thread library. My question is whether we need to move to T2 solaris thread library and use the option of -XX:-UseLWPSynchronization on JVM would help in the long run. As i am quire new to the JVM Hot Spot (excuse my lack of knowledge in this sphere), i am also posting the thread dump or parts of it here - I am reading them as dead locks but i could be wrong, would also appreciate some help on this matter to clarify what i am reading:
    "IS <ENERGYAUST#wm.ip.ebxml.MSH:process>" prio=5 tid=0x00a2e570 nid=0x12c in Object.wait() [63f7e000..63f819c0]
         at java.lang.Object.wait(Native Method)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.pool.ObjectPool.allocate(ObjectPool.java:248)
         - locked <0x97835bf8> (a java.lang.Object)
         at com.wm.util.pool.ObjectPool.allocate(ObjectPool.java:191)
         at com.wm.app.b2b.server.ThreadManager.runTarget(ThreadManager.java:83)
         at com.wm.app.b2b.server.ThreadManager.runTarget(ThreadManager.java:62)
         at com.wm.app.b2b.server.control.ControlledThreadPool.runTarget(ControlledThreadPool.java:359)
         at wm.ip.ebxml.coder.util.getEnvelopeStream(util.java:588)
         at sun.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:113)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:635)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:584)
         at com.wm.app.tn.route.RoutingActions.invokeWrapper(RoutingActions.java:959)
         at com.wm.app.tn.route.RoutingActions.invoke(RoutingActions.java:827)
         at wm.tn.route.route(route.java:750)
         at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:113)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:635)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:584)
         at wm.ip.ebxml.Receiver.processMessage(Receiver.java:588)
         at wm.ip.ebxml.Receiver.process(Receiver.java:186)
         at wm.ip.ebxml.MSH.process(MSH.java:165)
         at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:113)
         at com.wm.app.b2b.server.ServiceThread.run(ServiceThread.java:82)
         - locked <0xbb1b42e0> (a com.wm.app.b2b.server.ServiceThread)
         at com.wm.util.pool.PooledThread.run(PooledThread.java:105)
         - locked <0x9ad44eb8> (a com.wm.app.b2b.server.TMPooledThread)
         at java.lang.Thread.run(Thread.java:534)
    "IS <ENERGYAUST#wm.ip.ebxml.MSH:process>" prio=5 tid=0x00a2d980 nid=0x12b in Object.wait() [6407e000..640819c0]
         at java.lang.Object.wait(Native Method)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.pool.ObjectPool.allocate(ObjectPool.java:248)
         - locked <0x97835bf8> (a java.lang.Object)
         at com.wm.util.pool.ObjectPool.allocate(ObjectPool.java:191)
         at com.wm.app.b2b.server.ThreadManager.runTarget(ThreadManager.java:83)
         at com.wm.app.b2b.server.ThreadManager.runTarget(ThreadManager.java:62)
         at com.wm.app.b2b.server.control.ControlledThreadPool.runTarget(ControlledThreadPool.java:359)
         at wm.ip.ebxml.coder.util.getEnvelopeStream(util.java:588)
         at sun.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:113)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:635)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:584)
         at com.wm.app.tn.route.RoutingActions.invokeWrapper(RoutingActions.java:959)
         at com.wm.app.tn.route.RoutingActions.invoke(RoutingActions.java:827)
         at wm.tn.route.route(route.java:750)
         at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:168)
         at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
         at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:581)
         at com.wm.lang.flow.FlowState.step(FlowState.java:438)
         at com.wm.lang.flow.FlowState.invoke(FlowState.java:403)
         at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:982)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:113)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:635)
         at com.wm.app.b2b.server.Service.doInvoke(Service.java:584)
         at wm.ip.ebxml.Receiver.processMessage(Receiver.java:588)
         at wm.ip.ebxml.Receiver.process(Receiver.java:186)
         at wm.ip.ebxml.MSH.process(MSH.java:165)
         at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
         at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
         at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
         at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
         at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
         at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
         at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
         at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:411)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:521)
         at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:369)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:246)
         at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:113)
         at com.wm.app.b2b.server.ServiceThread.run(ServiceThread.java:82)
         - locked <0xbb1b4410> (a com.wm.app.b2b.server.ServiceThread)
         at com.wm.util.pool.PooledThread.run(PooledThread.java:105)
         - locked <0x9ad44f30> (a com.wm.app.b2b.server.TMPooledThread)
         at java.lang.Thread.run(Thread.java:534)
    "AuditRejectHandler" daemon prio=5 tid=0x009b23c8 nid=0x23 in Object.wait() [73681000..736819c0]
         at java.lang.Object.wait(Native Method)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:74)
         - locked <0x97800e18> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.app.store.impl.TSSimpleQueue._waitForMessage(TSSimpleQueue.java:585)
         at com.wm.app.store.impl.TSSimpleQueue.getWait(TSSimpleQueue.java:464)
         at com.wm.app.store.impl.TSSimpleQueueConsumer.getWait(TSSimpleQueueConsumer.java:37)
         at com.wm.app.audit.AuditFactory$AuditRejectHandler.run(AuditFactory.java:1646)
    "AuditRetryHandler" daemon prio=5 tid=0x007bc5c8 nid=0x22 in Object.wait() [73781000..737819c0]
         at java.lang.Object.wait(Native Method)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:74)
         - locked <0x97800ed0> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.app.store.impl.TSSimpleQueue._waitForMessage(TSSimpleQueue.java:585)
         at com.wm.app.store.impl.TSSimpleQueue.getWait(TSSimpleQueue.java:464)
         at com.wm.app.store.impl.TSSimpleQueueConsumer.getWait(TSSimpleQueueConsumer.java:37)
         at com.wm.app.audit.AuditFactory$RetryHandler.run(AuditFactory.java:1495)
    "AuditExceptionHandler" daemon prio=5 tid=0x009b1e30 nid=0x21 in Object.wait() [73881000..738819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x97800f90> (a com.wm.util.sync.CountingSemaphore)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:71)
         - locked <0x97800f90> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:56)
         - locked <0x97800f90> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.app.audit.AuditFactory$ExceptionHandler.run(AuditFactory.java:1410)
    "AuditProducer0" daemon prio=5 tid=0x009bb4e8 nid=0x20 in Object.wait() [73a81000..73a819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x97801000> (a com.wm.util.sync.CountingSemaphore)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:71)
         - locked <0x97801000> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.app.store.impl.TSSimpleQueue._waitForMessage(TSSimpleQueue.java:585)
         at com.wm.app.store.impl.TSSimpleQueue.getWait(TSSimpleQueue.java:464)
         at com.wm.app.store.impl.TSSimpleQueueConsumer.getWait(TSSimpleQueueConsumer.java:37)
         at com.wm.app.audit.AuditFactory$AuditProducerHandler.run(AuditFactory.java:1576)
    "TS-EventHandler" daemon prio=5 tid=0x005c1d20 nid=0x1f in Object.wait() [73981000..739819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x978010c8> (a com.wm.util.sync.LatchedSemaphore)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.sync.LatchedSemaphore.semWait(LatchedSemaphore.java:54)
         - locked <0x978010c8> (a com.wm.util.sync.LatchedSemaphore)
         at com.wm.util.sync.LatchedSemaphore.semWaitReset(LatchedSemaphore.java:101)
         - locked <0x978010c8> (a com.wm.util.sync.LatchedSemaphore)
         at com.wm.app.store.TransientStoreFactory$NotifyHandler.run(TransientStoreFactory.java:2173)
    "FSData Free Cache Handler" daemon prio=5 tid=0x006eca38 nid=0x1d in Object.wait() [73b81000..73b819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x97801130> (a com.wm.util.sync.CountingSemaphore)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:71)
         - locked <0x97801130> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:56)
         - locked <0x97801130> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.driver.data.fs.FSData$FreeCacheHandler.run(FSData.java:3976)
    "Thread-12" daemon prio=5 tid=0x009bc0a0 nid=0x1c in Object.wait() [73c81000..73c819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x97801140> (a com.wm.app.jdbc.JDBCConnPoolMgr$ConnectionTimeoutMgr)
         at com.wm.app.jdbc.JDBCConnPoolMgr$ConnectionTimeoutMgr.run(JDBCConnPoolMgr.java:394)
         - locked <0x97801140> (a com.wm.app.jdbc.JDBCConnPoolMgr$ConnectionTimeoutMgr)
    "FSData Free Cache Handler" daemon prio=5 tid=0x006ebcf0 nid=0x1b in Object.wait() [73d81000..73d819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x978011e8> (a com.wm.util.sync.CountingSemaphore)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:71)
         - locked <0x978011e8> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.util.sync.CountingSemaphore.semWait(CountingSemaphore.java:56)
         - locked <0x978011e8> (a com.wm.util.sync.CountingSemaphore)
         at com.wm.driver.data.fs.FSData$FreeCacheHandler.run(FSData.java:3976)
    "Thread-10" daemon prio=5 tid=0x00590d90 nid=0x1a in Object.wait() [73e81000..73e819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x978011f8> (a com.wm.app.repov4.server.RepoServer$RepoLockTimeoutMgr)
         at com.wm.app.repov4.server.RepoServer$RepoLockTimeoutMgr.run(RepoServer.java:1533)
         - locked <0x978011f8> (a com.wm.app.repov4.server.RepoServer$RepoLockTimeoutMgr)
    "Thread-9" daemon prio=5 tid=0x000e9f48 nid=0x19 in Object.wait() [74081000..740819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x978012b0> (a com.wm.driver.queue.data.DataQueue)
         at java.lang.Object.wait(Object.java:429)
         at com.wm.driver.queue.data.DataQueue.dequeue(DataQueue.java:310)
         - locked <0x978012b0> (a com.wm.driver.queue.data.DataQueue)
         at com.wm.driver.queue.data.DataQueue.dequeueCommit(DataQueue.java:260)
         - locked <0x978012b0> (a com.wm.driver.queue.data.DataQueue)
         at com.wm.driver.queue.data.DataQueue.dequeueCommit(DataQueue.java:254)
         - locked <0x978012b0> (a com.wm.driver.queue.data.DataQueue)
         at com.wm.app.repov4.server.RepoServerBase$RepoEventManager.run(RepoServerBase.java:224)
    "TxnData-Deadlock-Manager" daemon prio=5 tid=0x00799c18 nid=0x14 in Object.wait() [73f81000..73f819c0]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x97801338> (a java.lang.Object)
         at com.wm.util.data.TxnData$DeadlockManager.run(TxnData.java:4945)
         - locked <0x97801338> (a java.lang.Object)
    "Thread-2" daemon prio=5 tid=0x00104430 nid=0x12 in Object.wait() [74181000..741819c0]
         at java.lang.Object.wait(Native Method)
         at com.wm.util.queue.FSMTDirValuesHash$VHLockTimeoutMgr.run(FSMTDirValuesHash.java:448)
         - locked <0x978013b0> (a com.wm.util.queue.FSMTDirValuesHash$VHLockTimeoutMgr)
    "Log Thread" prio=5 tid=0x002e9f10 nid=0x11 in Object.wait() [74281000..742819c0]
         at java.lang.Object.wait(Native Method)
         at com.wm.util.sync.SimpleQueue.deq(SimpleQueue.java:171)
         - locked <0x97801458> (a com.wm.util.sync.SimpleQueue)
         at com.wm.util.sync.SimpleQueue.deq(SimpleQueue.java:126)
         - locked <0x97801458> (a com.wm.util.sync.SimpleQueue)
         at com.wm.app.b2b.server.ServerLogHandler$LogThread.run(ServerLogHandler.java:274)
    "Cron

    Hi,
    I've just found the following in another thread:
    The workaround for the bugID 6221832 (java being in another path than the default /usr/j2se/bin/ for Patch Manager 2.0 on Solaris 8) is to edit the pprosetup and pprosvc scripts
    from /usr/sbin/pprosvc :
    JAVACMD=/usr/j2se/bin/java
    edit pprosetup and pprosvc scripts file and set JAVACMD locale variable to newly java installed path and launch smpatch get command again
    Thank you. I've editted both scripts and changed the JAVACMD variable to be ${JAVA_HOME}/bin/java and now everything is working.
    Thanks.

  • Concurrency with locks and wait/signal. Is it ok?

    Hello,
    I'm relatively new in concurrency. I've write this code that seems to work, but I'm not sure if there is any error (the concurrency concepts are not still clear for me).
    In the following class "diskFile", I'll start 10 threads executing the class "diskCacheDataOneCall". The question is that the "populateCacheFromDisk" method should wait until 10 threads are finished and, if any thread produces an error, interrupt all threads and finish.
    The code seems to work, but I have some questions like if I should synchronize the static variables Lock and Condition before using them.
    Anyway, I'd like that an "expert" on concurrency tells me if this code is acceptable, or what kind of improvements can do (or, if there is some mistake, how to correct it).
    I've spent many time reading tutorials about concurrency, and this is the result. Really, I'm not sure if I'm doing the things well, that's why I need the opinion of an expert in order to get better on concurrency.
    Thanks in advance.
    public class diskFile
    // Static variables for threading.
    public static Lock lock = null;
    public static Condition cdFinished = null;
    public static int numActiveThreads = 0;
    public static Exception loadException = null;
    // Main function
    public static void populateCacheFromDisk() throws cacheServletException
    ArrayList<Thread> arrThread = new ArrayList<Thread>();
    // Init static variables.
    lock      = new ReentrantLock();
    cdFinished      = lock.newCondition();     
    numActiveThreads = 0;
    loadException = null;
    try
    // Iterate 10 times (for simplicity) ...
    for (int i = 0; i < 10; i++)
    // Create THREAD and store its reference
    Thread thr = new Thread(new diskCacheDataOneCall());
    thr.start();
    arrThread.add(thr);
    // Increment "numActiveThreads"
    lock.lock();
    numActiveThreads++;
    lock.unlock();
    // Her we wait while no error happens and still active threads
    lock.lock();
    while ( (loadException == null) && (numActiveThreads > 0) )
    cdFinished.await();
    // If an error happens in any thread, then interrupt every active thread.
    if (loadException != null)
    for (int i = 0; i < arrThread.size(); i++)
    Thread thr = arrThread.get(i);
    if (thr.isAlive()) thr.interrupt();
    throw loadException;
    catch (Exception e) { throw new cacheServletException(); }
    finally { lock.unlock(); }
    public class diskCacheDataOneCall implements Runnable
    public diskCacheDataOneCall() {}     
    public void run()
    try
         diskFile.getCacheDataFromDiskOneCall(); // Load data from disk.
    // Decrement "numActiveThreads"
         diskFile.lock.lock();
         diskFile.numActiveThreads--;
    catch (Exception e)
    diskFile.lock.lock();
    diskFile.loadException = e;
    finally
    // Always signal and unlock.
    diskFile.cdFinished.signal();
    diskFile.lock.unlock();
    }

    Hello David,
    Sorry but the code does not work. An IllegalMonitorStateException is throwed. Here I show you a simplified version (now with ThreadPoolExecutor):
       // Main class (it triggers "maxActive" threads)
       Lock lock  = new ReentrantLock();
       Condition cdFinished = lock.newCondition();       
       numActiveThreads = 0;
       loadException = null;
       try
        ExecutorService ex = Executors.newFixedThreadPool(numActiveThreads);
        for (int i = 0; i < numActiveThreads; i++) ex.execute(arrTasks.get(i));
        lock.lock();
        while ( (loadException == null) && (numActiveThreads > 0) )
                   cdFinished.await();
        ex.shutdown();
       catch (Exception e) { throw e; }
       finally { lock.unlock(); }
      // Every thread.
      public void run()
       try
        doSomething();
        diskFile.lock.lock();
        diskFile.numActiveThreads--;
       catch (Exception e)
        diskFile.lock.lock();
        diskFile.loadException = cse;
       finally
        diskFile.cdFinished.signal();
        diskFile.lock.unlock();
      }The exception is:
    // Fail in the "signal" (finally section)
    Exception in thread "pool-1-thread-1" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.signal(AbstractQueuedSynchronizer.java:1666)
    at com.vcfw.cache.cache.disk.diskCacheDataOneCall.run(diskCacheDataOneCall.java:44)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:595)
    // Fail in the "unlock" (finally section)
    Exception in thread "pool-1-thread-2" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:125)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1102)
    at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
    at com.vcfw.cache.cache.disk.diskCacheDataOneCall.run(diskCacheDataOneCall.java:43)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:595)
    Some threads fail executing the signal, and some threads fail executing ythe unlock. An IllegalMonitorStateException seems to mean that the lock was not acquired by the thread, but I'm not able to see the mistake.
    Can you help me?
    Thanks.

  • IPhone 4 spin lock

    How do I turn the spin lock on/off on my iPhone 4? This is the feature that allows you to turn the phone on its side &amp; the screen turns with it.

    Go to multitasking bar and scroll to left and click the rotation lock and your iPhone will stop rotating or it will be rotated!

  • Question on Thread concurrency

    If two threads execute the below method increment() concurrently, how many different final values of X are there? You may assume that initially X has value 0.
    void increment()
    int temp = x;
    temp = temp + 1;
    x = temp;
    }

    That's enough of these questions. It's not a homework service. Locking this thread.

  • Having a problem with threads and using locks

    I was hoping someone could give me some hits on getting my code to run properly. The problem I am having is I think my locks and unlocks are not working properly. Plus, for some reason I always get the same output, which is:
    Withdrawal Threads         Deposit Threads            Balance
    Thread 2 attempts $29 Withdrawal - Blocked - Insufficient Funds
    Thread 4 attempts $45 Withdrawal - Blocked - Insufficient Funds
    Thread 6 attempts $34 Withdrawal - Blocked - Insufficient Funds
    Thread 7 attempts $40 Withdrawal - Blocked - Insufficient Funds
                                    Thread 1 deposits $187          $187
                                    Thread 3 deposits $169          $356
                                    Thread 5 deposits $61           $417
    Press any key to continue...If someone can see the error I made and doesn't mind explaining it to me, so I can learn from it, I would appreciate that very much.
    /************Assign2_Main.java************/
    import java.util.concurrent.*;
    public class Assign2_Main
    {//start Assign2_Main
        public static void main(String[] args)
        {//start main
               // create ExecutorService to manage threads
               ExecutorService threadExecutor = Executors.newCachedThreadPool();
            Account account = new SynchronizedThreads();
            Deposit deposit1 = new Deposit(account, "Thread 1");
            Deposit deposit2 = new Deposit(account, "Thread 3");
            Deposit deposit3 = new Deposit(account, "Thread 5");
            Withdrawal withdrawal1 = new Withdrawal(account, "Thread 2");
            Withdrawal withdrawal2 = new Withdrawal(account, "Thread 4");
            Withdrawal withdrawal3 = new Withdrawal(account, "Thread 6");
            Withdrawal withdrawal4 = new Withdrawal(account, "Thread 7");
            System.out.println("Withdrawal Threads\t\tDeposit Threads\t\t\tBalance");
            System.out.println("------------------\t\t---------------\t\t\t-------\n");
            try
                threadExecutor.execute(withdrawal1);       
                threadExecutor.execute(deposit1);     
                threadExecutor.execute(withdrawal2);  
                threadExecutor.execute(deposit2);    
                threadExecutor.execute(withdrawal3);
                threadExecutor.execute(deposit3);       
                threadExecutor.execute(withdrawal4);
            catch ( Exception e )
                 e.printStackTrace();
                //shutdown worker threads
               threadExecutor.shutdown();
        }//end main
    }//end Assign2_Main/******************Withdrawal.java****************************/
    public class Withdrawal implements Runnable
    {//start  class Withdrawal
          *constructor
        public Withdrawal(Account money, String n)
             account = money;
             name = n;
        public void run()
        {//start ruin
             int newNum = 0;
                newNum = account.getBalance(name); 
               Thread.yield();
        }//end run
        private Account account;
        private String name;
    }//end  class Withdrawal/*******************Deposit.java***************/
    import java.util.Random;
    public class Deposit implements Runnable
    {//start class Deposit
          *constructor
        public Deposit(Account money, String n)
             account = money;
             name = n;
        public void run()
        {//start run
                try
                     Thread.sleep(100);
                   account.setBalance(random.nextInt(200), name);
                }// end try
                catch (InterruptedException e)
                  e.printStackTrace();
       }//end run
       private Account account;
       private Random random = new Random();
       private String name;
    }//end class Deposit/********************Account.java*****************/
    *Account interface specifies methods called by Producer and Consumer.
    public interface Account
         //place sum into Account
         public void setBalance(int sum, String name);
         //return  value of Account
            public int getBalance(String name);         
    } /**************SynchronizedThreads.java****************/
    import java.util.concurrent.locks.*;
    import java.util.Random;
    public class SynchronizedThreads implements Account
    {//start SynchronizedThreads
          *place money into buffer
        public void setBalance(int amount, String name)
        {//start setBalance
             // lock object
             myLock.lock();           
            sum += amount;
            System.out.println("\t\t\t\t" + name + " deposits $" + amount +"\t\t$"+ sum+"\n");       
               //threads are singnaled to wakeup
            MakeWD.signalAll();
              // unlock object                                                
            myLock.unlock();
           }//end setBalance
            *gets the balance from buffer
           public int getBalance(String name)
        {//start getBalance
             int NewSum = random.nextInt(50);
             //lock object
            myLock.lock();
            try
                 if(sum > NewSum)
                     //takes NewSum away from the account
                     sum -= NewSum;
                        System.out.println(name + " withdraws $" + NewSum +"\t\t\t\t\t\t$"+ sum+"\n");
                else
                     System.out.println(name +  " attempts $" + NewSum + " Withdrawal - Blocked - Insufficient Funds\n");                 
                     //not enough funds so thread waits
                        MakeWD.await();         
                //threads are singnaled to wakeup
                MakeD.signalAll();     
                }//end try
            catch (InterruptedException e)
                   e.printStackTrace();
            finally
                 //unlock object
                 myLock.unlock();
            return NewSum;     
         }//end getBalance
         private Random random = new Random();  
         private Lock myLock = new ReentrantLock();
         private Condition MakeD = myLock.newCondition();
         private Condition MakeWD = myLock.newCondition();
         private int sum = 0;
    }//end SynchronizedThreads

    You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
    However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
    You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
    Regds,
    SD
    N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
    Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM

  • High concurrency optimistic locking

    Hi there,
    We have an EJB method that roughly does the following; we have a number of buckets that may or may not be full. If one or more are not full we want it to find the one with the most space available and add the item there. Our main problem here is that this method can be called upwards of 1000 times per second and we're now looking for an efficient way to solve the concurrency issue of two different calls both thinking bucket X has space left even though one of the two calls will fill it up :
    THREAD 1 : findEmptyBucket() returns BUCKET1 (1 SPOT LEFT)
    THREAD 2 : findEmptyBucket() returns BUCKET1 (1 SPOT LEFT)
    THREAD 1 : addItemToBucket(BUCKET1) <- FULL NOW
    THREAD 2 : addItemToBucket(BUCKET1) <- WRONG
    Since only optimistic locking is available in the spec for some reason I think the "EJB3" approach is basically (pseudoish) :
    while(!succeeded) {  
        try {  
            Bucket b = findEmptyBucket(...); // Will throw OptimisticLockException?  
            addItemToBucket(b, item);  
            succeeded = true;  
        catch(OptimisticLockException e) {}  
    } This seems horribly inefficient for a call that is almost guaranteed to require dozens of retries during peak hours. Is there any way to optimize this in such a way that we don't have to use optimistic locking? We're trying to solve this without using vendor specific solutions but EJB3 seems to lack the necessary functionality. Suggestions definitely welcome, evne if they are "that's the only way to do it" ;)
    Thanks!

    I think the OptimisticLockingException is thrown after-the-fact. So, if the addItemToBucket() method does a commit (flush), it will generate the exception rather than the find method. Otherwise, if there is no explicit commit call, the exception will be thrown when the EJB method that holds the while loop returns.
    If performance is critical, maybe a Stateful SessionBean with a Stateless Facade would work better. Create a Stateless SessionBean with an addItem() method and a reference to a single stateful bean. The implementation of the stateful session bean would be something like the following standalone program. The stateful bean would have an addItem() method too, but would keep track of a pool of resources internally.
    class ItemBucket { Item i; }
    class Item { String data; }
    class NoBucketsAvailableException extends Exception {}
    public class bucket {
        final static int POOL_SIZE = 4;
        ItemBucket[] bucketPool = new ItemBucket[POOL_SIZE];
        Object[] bucketLocks = new Object[POOL_SIZE];
        void initBucketPool() {
         for(int i=0; i<POOL_SIZE; i++)  {
             bucketPool[i] = new ItemBucket();
             bucketLocks[i] = new Object();
        void addItemToEmptyBucket(Item _i) throws NoBucketsAvailableException {
         int i=0;
         for(; i<POOL_SIZE; i++) {
             if( bucketPool.i == null ) { // possible empty bucket
              synchronized(bucketLocks[i]) {
              if( bucketPool[i].i == null ) {  // double checked locking
                   bucketPool[i].i = _i;
         if( i >= POOL_SIZE) { throw new NoBucketsAvailableException(); }
    public static void main(String[] args) {
         bucket app = new bucket();
         app.initBucketPool();
         Item item = new Item();
         item.data = "test";
         try {
         app.addItemToEmptyBucket(item);
         catch(NoBucketsAvailableException exc) {}

  • Concurrent File Read Question

    Hi:
    I am writing a multi-thread program to read from one large file. Different thread will read different part of the file so they do not interfere.
    I am considering using the java.nio's memory-mapped I/O since the file is pretty large. But I cannot find any document regarding
    the thread-safeness of the API.
    Suppose the file is mapped to a MappedByteBuffer, and two threads issue two gets() operations concurrently, can the two gets() run concurrently or the second one has to be blocked until the first one returns, or even worse, incorrect result may be returned?
    Thanks,
    -Yi
    Edited by: grantguo on Oct 22, 2008 11:52 PM

    You don't know what flock() and flock16() function are in Platform OS's.Your guesswork about the extent of my knowledge is just as uninformed and irrelevant as everything else you've posted here. You're certainly in no position to lecture me about flock() when you don't know what it does yourself.
    So a very good clue about java thread-safeness implicitly is java.nio.channels.FileChannel methods for locking and locking zones of a file.In other words you haven't even read the Javadoc for the solution you're recommending. The quotation in Roy's post above shows that FileLock cannot possibly be the solution to any threading problem.
    The rest of your posting is equally irrelevant and erroneous. I wrote a paper criticising the semantics of lockf(), now flock(), in 1984. Whatever flock16() may be, Google doesn't know what it is either. Both are irrelevant. Every OS I have ever used allows concurrent reads to a file, unless you lock it. Neither Unix nor Windows has a 'VM level'. The 'JVM base drivers' are a figment of your imagination. There are no drivers in the JVM. What you're talking about is just the JVM.
    The OP's 'main worries' are precisely this: whether it is thread-safe to read a file via multiple threads via a MappedByteBuffer. He has no need to lock the file and it wouldn't solve this problem even if he did. It wouldn't solve any problem unless there were simultaneous writers to the file, which he hasn't mentioned.
    He may need to synchronize the threads against each other because MappedByteBuffer isn't documented to be thread-safe (although I suspect that the methods that take an offset argument actually are).
    Most of this has already been stated above, before you appeared in the discussion. You're just wasting time and space with your erroneous and irrelevant contributions. You've been warned about this before and you've been blocked before on account of it. Moderators are watching this thread and your other postings.

  • Concurrent DB Locking

    Hi,
    I am using the Berkeley's CDB type to create a database. The access method is BTree. In the application, typically there will be a single writer process that keeps inserting/updating records in this DB. There is another reader process (multi-threaded). Each of the threads in this process opens a READ Cursor on this DB, fetches some records based on certain filters and closes the cursor when done.
    What happens here is that when any of the reader threads opens the Cursor, the Wrter process is blocked, unless the Reader thread closes the Cursor. This means that the Reader creates a database-level Read-lock. How can this be optimized?
    Another question here is that, if any Reader thread is killed, the writer is blocked indefinitely. I know that there should be a dead-lock detector run periodically which will free locks appropriately. But without this dead-lock detector running, isnt there an optimized way of implementing a solution for this?
    Regards,
    Ravi Nathwani

    Hello,
    From the documention:
    http://www.oracle.com/technology/documentation/berkeley-db/db/ref/cam/intro.html
    Read cursors may open and perform reads without blocking
    while a write cursor is extant. However, any attempts to
    actually perform a write, either using the write cursor
    or directly using the DB->put or DB->del methods, will block
    until all read cursors are closed. This is how the
    multiple-reader/single-writer semantic is enforced, and prevents
    reads from seeing an inconsistent database state that may be an
    intermediate stage of a write operation.
    This sounds like your situation.
    Two of the sequences which can cause a thread to block itself
    indefinitely are:
    1. Keeping a cursor open while issuing a DB->put or
    DB->del access method call.
    2. Not testing Berkeley DB error return codes (if any
    cursor operation returns an unexpected error, that cursor
    must still be closed).
    Could you be running into these?
    Thanks,
    Sandra

  • Hashtable locking question

    I see that the put and get methods of Hashtable are synchronized, which is great for multi-thread execution, however, if outside the Hashtable class I use
    Hashtable t = new Hashtable();
    synchronized(t) {
       // loop over the hashtable in here and print out the values
    }is that synchronized block using the same lock as Hashtable's internal one? In other words, if I'm inside that synchronized block am I assured that no other thread can call get() or put()?
    I'm just looking for the proper way to iterate over the Hashtable while assuring myself it won't be modified.
    thanks!!!

    I looked up the SynchronizedMap source and don't see a big difference between it and Hashtable. SM uses synchronized blocks in every function and Hashtable uses synchronized methods. Is their a difference? If it's just a matter of one way being preferred over another let me know.
    Also, I'd still like an answer to my original question about the locks...is the object lock in a synchronized block the same as the class lock on that object's synchronized methods (see my example in post 1)?
    thanks!

  • Trivial Lock Question - nested synchronized instance method call

    Hi there. I have a question surrounding the following code block:
            public synchronized void bow(Friend bower)
                System.out.format("%s: %s has bowed to me!%n",
                        this.name, bower.getName());
                bower.bowBack(this);
            public synchronized void bowBack(Friend bower)
                System.out.format("%s: %s has bowed back to me!%n",
                        this.name, bower.getName());
            }If the bow method is invoked by the currently executing thread that has obtained the lock on the current instance and the
    call "bower.bowBack()" is invoked, what happens? Is the lock released then obtained again by the current thread? or does it hold onto it since the method
    "bowBack" is called within the method "bow"?
    Thank you!
    Regards

    thank you as always mr. verdagen!
    regards

  • FileChannel.lock() question

    Hi
    (code below)
    According to the documentation on the FileLock.lock() method...
    " An invocation of this method will block until the region can be locked, this channel is closed, or the invoking thread is interrupted, whichever comes first. "
    So I would expect whichever thread that gets executed second to wait patiently until a lock on the (0,23) portion of the file can be obtained.
    However, I get a "Java.nio.channels.OverlappingFileLockException" when the second thread attemps to acquire a lock on the (0,23) portion of the file.
    How can I get a thread to wait until it can acquire a lock on the (0,23) portion of the file can be obtained... and then acquire the lock???
    Thanks for your help...
    public static void main(String[] args) {
      try{
        final File f = new File("<filename>");
        final RandomAccessFile raf = new RandomAccessFile(f, "rw");
        final FileChannel channel = raf.getChannel();
        class tobj implements Runnable {
          public void run(){
            try{
              channel.lock(0, 23, true);
              System.out.println(Thread.currentThread() + " is done");
            catch(Exception e){
              System.out.println(e);
        new Thread(new tobj()).start();
        new Thread(new tobj()).start();
        //raf.close();
      catch(Exception e){
        System.out.println(e);
    }

    I have a flat file that is accessed by multiple threads. Speed is of utmost importance. If thread A wants to read bytes 1-50 and thread B wants to overwrite bytes 100 - 150, the program should allow the threads to do this concurrently as the threads will not affect each other. But if thread A wants to overwrite bytes 1 - 50 then immediately after thread B wants to read the same area (bytes 1 - 50), then thread B should wait until a is finished with that area of the file.
    Multiple threads should be able to read from the same area at the same time.
    But when a thread wants to write to an area of a file, it should have sole control of that area until it is finished.
    Any ideas..
    I really appreciate you help..
    I really appreciate you help..

  • Resource busy time out oracle message - Concurrency and Locks

    I have a requirement to generate gapless invoice and receipt number in our application. so i have currently used the below approach.
    a. created table with a column to hold the invoice and receipt number sequence value.
    b. whenever transaction gets succeed. i will lock the table which holds the invoice number and receipt number inorder to avoid the sequential number slipages.
    Issue
    1. since the application belongs to online payment through portal by customers, when concurrent users trying to pay and while generating receipt number's, i am facing with "resource busy time out" message frequently. Here i noticed when user1 locks the table to access the receipt number value and session is not committed or rollback and another session user2 trying to access the same resource, in this scenario i am facing this error.
    Frequency of encountering this error is low, but customer was telling us this error is show stopper and affects normal business.
    Is there any alternative solution or method can be applied to overcome this problem?
    Current SQL used in application
    cursor <cursor name> is.
    select <column_name>
    into <variable>
    from <table name>
    for update of wait 5
    update <table name> set <column name> = value + 1
    where current of <cursor name>

    1e0ea4a1-1610-4dec-a44c-4ee1f46ba1a4 wrote:
    I have a requirement to generate gapless invoice and receipt number in our application. so i have currently used the below approach.
    Engage the business and inquire WHY this "requirement" exists. I have personally never seen an audit requirement wherein invoices MUST be devoid of gaps (that's not to say they do not exist, just that I've never seen one
    They certainly must be unique, but that's what a sequence will do for you. If the business absolutely needs gapless information, then they will have to be willing to pay the price which is going to be longer transaction times (as requests queue in a busy system to get this sought after gapless resource). Your job is to explain this to them ... nothing comes without a cost.
    The only thing you can really do (assuming you engage the business and the requirement doesn't change) is ensure the transactions are designed in such a manner that
    1) they complete as fast as possible AND that the locking is done at the latest possible stage of the transaction
    2) there is no user interaction (you cannot allow the users a "review" screen of any sort ... because users get silly sometimes and go for a coffee while reviewing things)
    Cheers,

  • Need some design idea for a multi- thread  concurrent system

    I am totally new to this area. Hope ppl can give me some suggestion for the following project.
    The project is using socket to deal with huge concurrent data. Server will send me more than 50K (maybe more) XML strings in a short time.
    I need parse strings and save them in the data structure.
    What I have done is using ExecutorService to deal with this problem. Unfortunately, it's already too slow even I don't save data into data structure.(data structure will cause synchronization problem, and make system even worse).
    I was required to develop this software in a single machine and windows based OS.
    Should I only use single thread to do this project? or some other strategy?
    Can anybody give me some suggestion.
    Thanks so much.

    Peter. Thanks again.
    Could you help me to take a look at this code. Appreciate that.
    ThreadPool class:
    protected ExecutorService threadPool = Executors.newFixedThreadPool(5);
       incoming = new Socket("127.0.0.1", port1);
       outcoming = new Socket("127.0.0.1", port2);
       out = new PrintWriter(outcoming.getOutputStream(), true);
       isr = new InputStreamReader(incoming.getInputStream());
       is = new BufferedReader(isr);
    while (true) {
         String str;
         str = is.readLine();
         if (str == null) {
                 cleanup();
                 closeSocket();
                 printout();
            } else {        
                             this.threadPool.submit(new WorkerRunnable(str,          
                                                             "Thread Pooled Server"));
           }WorkerRunnable class:
    public void run() {
    try {
                SAXBuilder builder = new SAXBuilder();
                InputSource is = new InputSource( );
                is.setCharacterStream(new StringReader(xmlString));
                org.jdom.Document doc = builder.build(is);
                org.jdom.Element root = doc.getRootElement();
                org.jdom.Element order = root.getChild("Changes");
                List orderList = order.getChildren("OrderChange");
                if (orderList.size() != 0) {
                               org.jdom.Element orderchange = (org.jdom.Element) orderList.get(0);
                               String price = orderchange.getAttribute("orderPrice").getValue();
                               String quantity = bookchange.getAttribute("orderQuantity").getValue();
                               String symbol = bookchange.getAttribute("orderName").getValue();
                                } catch(Exception e)
                              {}

  • Threaded Sudoku solver - Assignment question (NOT LOOKING FOR ANSWERS  )

    Hi All,
    I'm going to be upfront and point out this is an assignment that i'm currently working on and i'm not receiving much in the way of feedback from the class forums.
    This is currently a 4th year OO assignment for UNSW Australia.
    What I am having trouble doing is figuring out where my program is deadlocking or dying. There have been a number of requirements set out by the assignment, basically no synchronization, no locking. We are able to use volatile, atomic, immutable and thread-local objects. The task is to find all solution for a given N x N sudoku problem using X number of threads. I have successfully built the solver (X = 0) without too much trouble and I thought i had managed to modify the recursive algorithm to suit but unfortunately I think I have come unstuck.
    Any generalized tips would be appreciated when implementing threads that utilise checking flags to determine when the thread is finished processing.
    Kind Regards,
    Chris Gibbs

    Honestly, I think that recursion (as you stated) would be the easiest way to have solved this problem. But as you stated, threads must be used to solve this problem as a requirement of the project...
    You could easily launch a Thread each time instead of calling your recursive method... that could possibly result in a crap load of threads, but the idea would work.
    Definitely take a look at the SwingWorker class here if you're able to use J2SE 6: [http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html|http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html]
    I currently use it while gathering data from several websites at the same time. What I did was create and execute() X number of MySwingWorker objects to collect the data, while they are not complete (i.e. MySwingWorker.isDone() is false) I just Thread.sleep(...).
    Give it a try. It may suit your needs.

Maybe you are looking for

  • How to block one of wireless network

    Hi there, I have Airport Extreme with 2 wireless networks, one for my iMac and my wife's iPad another one is for kids PCs. All of us are connected only wireless. Question, how shall I block the kids network my configuration, now when I block the Airp

  • The data type DEC while downloading from ALV to EXCEL

    The data type DEC while downloading from ALV to EXCEL is giving some invalid data . Ex : In ALV field is the time difference in  hours:minutes   if the value is  :23 in Excel it will be 22:59 . Please Suggest immediately

  • Modifying existing theme

    Hi ! I use N79. I just want to modify the theme to add a wallpaper so that it sit nicely in the middle of the screen. Where can I find the existing themes ? Thanks

  • Why not change the  Macintosh HD to a shorter name.

    I have a friend that picked up a Mac mini with OS X 10.5.8 and one for the first things I noticed was the previous owner had changed the name of the single drive from Macintosh HD to a shorter name I recall reading somewhere that it is not a good ide

  • STO shipping data tab not appearing in PO hence cannot make deli.by VL10B

    Hi, I am doing stock transfer order setting in define shipping data for plant in SPRO (stock transfer order setting ).In documentation it is mentioned that  we had to set customer number of receiving plant and also sales org/dis/channel for supplying