Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

ConcurrentModificationException when multiple threads login
 Post subject: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Mon 09 Feb, 2015, 22:25 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

I'm running the platform(2.43.2) and API(2.12.6) release.
When I try to login with multiple threads, then sometimes this exception occurs:

java.util.concurrent.ExecutionException: java.util.ConcurrentModificationException
   at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
   at java.util.concurrent.FutureTask.get(FutureTask.java:111)
   at com.dukascopy.dds2.greed.market.LiveCurrencyMarketProcessingThread.run(LiveCurrencyMarketProcessingThread.java:116)
Caused by: java.util.ConcurrentModificationException
   at java.util.HashMap$HashIterator.nextEntry(HashMap.java:894)
   at java.util.HashMap$ValueIterator.next(HashMap.java:922)
   at com.dukascopy.api.impl.connect.DCClientImpl$9.tickReceived(DCClientImpl.java:857)
   at com.dukascopy.dds2.greed.market.LiveCurrencyMarketProcessingThread$1.run(LiveCurrencyMarketProcessingThread.java:135)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
   at java.util.concurrent.FutureTask.run(FutureTask.java:166)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
   at java.lang.Thread.run(Thread.java:722)


As with the other bugs, this exception does occur 1 out of 5 times.
Thanks for fixing this.

PS: ConcurrentHashMap as temporary fix?! ;-)


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Tue 10 Feb, 2015, 09:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello FXjuxe!

Provided log tells us that you are actually using older SDK version than latest 2.43.2/2.12.6. Please make sure that maven has updated you project correctly.


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Tue 10 Feb, 2015, 10:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Also please note that Standalone API does not provide ability to maintain multiple simultaneous logins from one application. Multiple threads won't help as ClientFactory.getDefaultInstance() always returns the same object.


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Tue 10 Feb, 2015, 22:59 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

You are right that I mistakenly have used the wrong jar.
This exception persists though(also with API(2.12.6)).
I've checked when this exceptions occures and it is not related to the login process.
I could narrow down the problem to the point where the threads call
client.startStrategy(...)

I suspect that some Dukascopy thread notifies all current running strategies which are stored in a List or other non-concurrent container.
Now, one of my threads calls
client.startStrategy(...)
while the Dukascopy thread loops through the already listed strategies.
This should result in the above exception.
Would it be much of a problem to use a concurrent-modifiable List instead, so that we can start and stop strategies at any time?

Thanks,
Juergen

PS: Here is the new log
java.util.concurrent.ExecutionException: java.util.ConcurrentModificationException
   at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
   at java.util.concurrent.FutureTask.get(FutureTask.java:111)
   at com.dukascopy.dds2.greed.market.LiveCurrencyMarketProcessingThread.run(LiveCurrencyMarketProcessingThread.java:116)
Caused by: java.util.ConcurrentModificationException
   at java.util.HashMap$HashIterator.nextEntry(HashMap.java:894)
   at java.util.HashMap$ValueIterator.next(HashMap.java:922)
   at com.dukascopy.api.impl.connect.DCClientImpl$7.tickReceived(DCClientImpl.java:794)
   at com.dukascopy.dds2.greed.market.LiveCurrencyMarketProcessingThread$1.run(LiveCurrencyMarketProcessingThread.java:135)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
   at java.util.concurrent.FutureTask.run(FutureTask.java:166)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
   at java.lang.Thread.run(Thread.java:722)

With API 2.12.6(DCClientImpl.java:794 differs)


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Wed 11 Feb, 2015, 09:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We will investigate.


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Wed 11 Feb, 2015, 09:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Also it would be really nice if you could provide application+strategy pair that replicates the issue.


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Wed 11 Feb, 2015, 16:24 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
It is not always trivial to extract a working example :-)
But here it is:
package com.dukascopy.testrunner;

import java.util.logging.Logger;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.dukascopy.api.system.ClientFactory;
import com.dukascopy.api.system.IClient;
import com.dukascopy.api.system.JFAuthenticationException;
import com.dukascopy.api.system.JFVersionException;

public class Example1 {

    private final static Logger logger = Logger.getLogger(Example1.class.getName());

    public static void main(String[] args) throws JFAuthenticationException, JFVersionException, Exception {
        Example1 testRunner = new Example1();
        testRunner.run();
    }

    public void run() throws JFAuthenticationException, JFVersionException, Exception {
        IClient client = ClientFactory.getDefaultInstance();
        client.connect("https://www.dukascopy.com/client/demo/jclient/jforex.jnlp", "password", "username");
        for (int i = 0; i < 10; ++i)
            if (!client.isConnected())
                Thread.sleep(500);

        for (int i = 0; i < 30; ++i) {
            MyThread myThread = new MyThread(client);
            Thread.sleep(300);
            myThread.run();
        }
    }

    private class MyThread implements Runnable {

        private IClient client;

        public MyThread(IClient client) {
            this.client = client;
        }

        @Override
        public void run() {
            MyStrategy myStratgey = new MyStrategy();
            client.startStrategy(myStratgey);
        }
    }

    private class MyStrategy implements IStrategy {

        @Override
        public void onAccount(IAccount arg0) throws JFException {
            // TODO Auto-generated method stub

        }

        @Override
        public void onBar(Instrument arg0, Period arg1, IBar arg2, IBar arg3) throws JFException {
            // TODO Auto-generated method stub

        }

        @Override
        public void onMessage(IMessage arg0) throws JFException {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStart(IContext arg0) throws JFException {
            logger.info("Strategy started on thread " + Thread.currentThread().getId());
        }

        @Override
        public void onStop() throws JFException {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTick(Instrument arg0, ITick arg1) throws JFException {
            // TODO Auto-generated method stub

        }
    }
}


Run this program 10 times and there should be the above exception.
As you see, the login is done in the main thread while the strategy starting is done in subthreads.
Whenever there is a tick to be distributed to the strategies and a new strategy gets started, then this happens.


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 1   New post Posted: Fri 13 Feb, 2015, 10:33 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

could you reproduce the problem?


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Wed 25 Feb, 2015, 08:41 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

I want to add that the same Problem exists when starting multiple plugins within the threads.
So it does not matter if one uses strategies or plugins.


 
 Post subject: Re: ConcurrentModificationException when multiple threads login Post rating: 0   New post Posted: Thu 26 Feb, 2015, 17:18 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Should be fixed in next SDK/API release.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com