Dukascopy
 
 
Wiki JStore Search Login

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

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

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

Thread error
 Post subject: Thread error Post rating: 0   Post Posted: Tue 12 Jul, 2011, 01:42 

User rating: -
I'm trying to record data in DB. I used IHistory to colect the bars from the latest 3 months for every instruments.
I colect each instrument, record in DB, for BID side then for ASK side.
The system is running some of the following messages show up in console:
"Strategy thread queue overloaded with tasks. Ticks in queue - 35, bars - 0, other tasks - 568"?

After some of this message appears in the console, an error occurs:
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(Unknown Source)
at java.nio.ByteBuffer.allocate(Unknown Source)
at org.apache.mina.common.SimpleByteBufferAllocator.allocate(SimpleByteBufferAllocator.java:45)
at org.apache.mina.common.ByteBuffer.allocate(ByteBuffer.java:225)
at org.apache.mina.common.ByteBuffer.allocate(ByteBuffer.java:214)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:210)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45)
at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:485)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
at java.lang.Thread.run(Unknown Source)

I had already tryed to kill every created object that is not in use anymore, but it didn't work.
I thought the range between dates were to long but works for one side and for the beginning of the other one...
What could it be?

Here goes the code I'm running:
            String strPeriod = period.name();
            List<IBar> barras = history.getBars(instrument, period, side,
                  dateFrom, dateTo);
            if (barras.size() != 0) {
               for (int i = 0; i < barras.size(); i++) {
                  IBar barra = barras.get(i);
                  boolean isWknd = TrataDiaHora
                        .IsWeekend(barra.getTime());
                  if (!isWknd) {
                     this
                           .adicionaBar(barra, side, strPeriod,
                                 instrument);
                  }
                  barra = null;
               }
            }
            barras = null;
            dtNow = null;
            dtFrom = null;
            dtTo = null;


Please help!
Thanks.
Eduardo.


 
 Post subject: Re: Thread error Post rating: 0   Post Posted: Tue 12 Jul, 2011, 11:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See Methods that return historical feed data section of:
https://www.dukascopy.com/wiki/index.php?title=IHistory


 
 Post subject: Re: Thread error Post rating: 0   Post Posted: Wed 13 Jul, 2011, 00:54 

User rating: -
I downloaded "ReadBarsExemple.java" and a boolean field is declared named "executed".
Within the "onTick" method compares this field that is never initialized, at least so far as I can see.
My question is onTick gets field "executed" initialized? Where can I find come other properties like this? Is there something called automaticaly like this in "onTick" and "onBar" methods?

Thanks.

Eduardo.


 
 Post subject: Re: Thread error Post rating: 0   Post Posted: Wed 13 Jul, 2011, 03:58 

User rating: -
Hi there!

I've tryed with readBars() instead of getBars() and guess what?
Exception in thread "Thread-7" java.lang.OutOfMemoryError: Java heap space

Here goes the code:
      for (Instrument instrument : Instrument.values()) {
         for (OfferSide side : OfferSide.values()) {
            DateTime dtFrom = barDAO.pegaDataFrom(period, side, instrument);
            DateTime dtTo = barDAO.pegaDateTo(period);
            System.out.println("Data From é: " + dtFrom);
            System.out.println("Data To é: " + dtTo);
            if (!executed) {
               console.getOut().println("Calling readBars method");
               history.readBars(instrument, period, side, dtFrom
                     .getMillis(), dtTo.getMillis(),
                     new LoadingDataListener() {
                        public void newTick(Instrument instrument,
                              long time, double ask, double bid,
                              double askVol, double bidVol) {
                           // no ticks expected, because we are loading
                           // bars
                        }

                        public void newBar(Instrument instrument,
                              Period period, OfferSide side,
                              long time, double open, double close,
                              double low, double high, double vol) {
                           ++numberOfBarsLoaded;
                           boolean isWknd = TrataDiaHora
                                 .IsWeekend(time);
                           if (!isWknd) {
                              Bar bar = new Bar();
                              bar.setClose(close);
                              bar.setHigh(high);
                              bar.setLow(low);
                              bar.setOpen(open);
                              bar.setTime(time);
                              bar.setVolume(vol);
                              barDAO.adicionaBar(bar, side, period
                                    .name(), instrument);
                           }
                        }
                     }, new LoadingProgressListener() {
                        public void dataLoaded(long startTime,
                              long endTime, long currentTime,
                              String information) {
                           console.getOut().println(information);
                        }

                        public void loadingFinished(
                              boolean allDataLoaded, long startTime,
                              long endTime, long currentTime) {
                           if (allDataLoaded) {
                              console.getOut().println(
                                    "All data loaded succesfully, number of bars loaded: "
                                          + numberOfBarsLoaded);
                              context.stop();
                           } else {
                              console
                                    .getOut()
                                    .println(
                                          "For some reason loading failed or was canceled by the user");
                              context.stop();
                           }
                        }

                        public boolean stopJob() {
                           return false;
                        }
                     });
               console.getOut().println(
                     "Exited readBars method, bars read - "
                           + numberOfBarsLoaded);
            }
         }
      }
      executed = true;
      context.stop();



 
 Post subject: Re: Thread error Post rating: 0   Post Posted: Wed 13 Jul, 2011, 13:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
https://www.dukascopy.com/wiki/index.php?title=IHistory states:
Quote:
getBars and getTicks return a List of bars and ticks correspondingly, thus taking some amount of the memory. It is not recommended to call these methods knowing that it could return thousands or even millions of ticks and cause OutOfMemoryException. Though normally it is ok to call getBar with shift parameter in 0-10 range, since it is very unlikely it will require server access to get the data.
Hence, the exception you are facing is a result of a restriction of java and its settings, not JForex API. So consider working with smaller chunks of bars at a time OR increasing the the java heap size if it is vital for your strategy to work with large quantities of historical bars at a time.


 

Jump to:  

cron
  © 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