Concurrency
JasonS
Posts: 229
Anyone have a good way to transfer execution from a Timer's Thread back to the Thread that called it when times up?
0
Comments
If you are just looking to link something to the tail of another thread Thread.join() is what you are after. This will pause the thread that it is called from until the thread you are joining completes.
I was trying to use a CountDownLatch, but it is throwing an IOException when it encounters the await().
This code requires Master Firmware 4.x.x Java Libraries
This is the Output:
(0000051591) Framework launched
(0000052248) Creating Thread Pool
(0000052415) AmxSslServerSocket(int,int): got called
(0000055100) Device Access: No DriverLocators found
(0000056433) Morpheus: Starting devicesdkrt.jar
(0000062868) Morpheus: Starting snapirouter.jar
(0000078798) timer1 started
(0000078824) InnerRunnable Thread Started
(0000078826) timer2 started
(0000078828) cdl.await() Exception
(0000078829) java.io.IOException
(0000078833) at sun.misc.Unsafe.compareAndSwapObject (Native Method)
(0000078835) at java.util.concurrent.locks.AbstractQueuedSynchronizer.compare
AndSetHead (Unknown Source, bco=9)
(0000078837) at java.util.concurrent.locks.AbstractQueuedSynchronizer.enq (Un
known Source, bco=32)
(0000078838) at java.util.concurrent.locks.AbstractQueuedSynchronizer.addWait
er (Unknown Source, bco=47)
(0000078839) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcqui
reSharedInterruptibly (Unknown Source, bco=7)
(0000078841) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire
SharedInterruptibly (Unknown Source, bco=27)
(0000078892) at java.util.concurrent.CountDownLatch.await (Unknown Source, bc
o=8)
(0000078894) at com.ctsi_usa.duet.virtual.test.dr1_0_0.VirtualTest$InnerRunna
ble.run (VirtualTest.java:123)
(0000078895) at java.lang.Thread.run (Unknown Source, bco=16)
(0000080081) SNAPIRouter: UtilityComponent loaded
(0000080207) SNAPIRouter: ModuleComponent loaded
(0000083815) timer1 code ran in TimerDaemon
(0000086829) timer2 cdl.countDown() running in TimerDaemon
Output:
(0000046272) Framework launched
(0000046929) Creating Thread Pool
(0000047141) AmxSslServerSocket(int,int): got called
(0000049256) Device Access: No DriverLocators found
(0000050594) Morpheus: Starting devicesdkrt.jar
(0000055953) Morpheus: Starting snapirouter.jar
(0000072411) InnerRunnable Thread Started
(0000073642) SNAPIRouter: UtilityComponent loaded
(0000073761) SNAPIRouter: ModuleComponent loaded
(0000080500) SyncTimer timed out in TimerDaemon
(0000080502) code after sync.doWait() running in InnerRunnable Thread