I wrote a JForex Strategy that needs to spawn a number of threads to execute concurrently. Concurrent multithreading is essential because without it this strategy is impossible to implement. The threads receive tick data through BlockingQueues and use other BlockingQueues to send results to each other and back to the Strategy. I implemented threads using Java 7 standard runnables and task.start() from the Strategy. The code is made as to not create any delays in executing the Strategy's onTick method. Everything works very fine except that from time to time Historical Tester stops sending ticks. This happens for both low and high test speed and also while running within JForex Client.
I thought that maybe it would be better to create and manage threads using finalContext.executeTask(task) according to
https://www.dukascopy.com/wiki/#Threading. So, I wrote a test ConcurrentThreads.java. Here I face difficulty in trying to run two threads simultaneously. Please try to run it in the JForex client.
The ConcurrentThreads Console output is:
...
15:37:13 NamedTask: taskOne - ticker:71 <*><*><*><*><*><*><*><*><*><*>
15:37:12 NamedTask: taskOne - ticker:70 <*><*><*><*><*><*><*><*><*><*>
15:37:11 NamedTask: taskOne - ticker:69 <*><*><*><*><*><*><*><*><*><*>
...
With concurrent execution the expected output should contain mixed prints from taskOne and taskTwo, like this:
...
15:37:13 NamedTask: taskTwo - ticker:71 <*><*><*><*><*><*><*><*><*><*>
15:37:12 NamedTask: taskOne - ticker:71 <*><*><*><*><*><*><*><*><*><*>
15:37:12 NamedTask: taskTwo - ticker:70 <*><*><*><*><*><*><*><*><*><*>
15:37:11 NamedTask: taskOne - ticker:70 <*><*><*><*><*><*><*><*><*><*>
15:37:11 NamedTask: taskTwo - ticker:69 <*><*><*><*><*><*><*><*><*><*>
...
Question 1: is it possible to run a few tasks concurrently, if they are created and started from JForex strategy using finalContext.executeTask(task) & task.start()? What must I change in my ConcurrentThreads.java to get simulataneous output from fom both taskOne and askTwo?
Question 2: Have you got any clue why feeding of ticks stops when I run Strategy + multitasking / standard runnables?
The problem is quite important since the strategy is getting good results and I'd like to prepare the final version for live execution. But it can't stop, of course.