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.

Timer (do something every x seconds)
 Post subject: Timer (do something every x seconds) Post rating: 0   New post Posted: Wed 20 Oct, 2010, 18:35 

User rating: 0
Joined: Wed 20 Oct, 2010, 16:06
Posts: 6
Hello. I'm new to jForex and to Java (although I know C/C++). I'd like to implement a timer in my strategy so that from the moment I start it, a task is completed every x seconds. I googled a bit and tried to merge what I found with my strategy code. The result: https://paste.pocoo.org/show/278054/

Please, look only until
public void onStart
because the rest is not important right now. With this setup I get the following errors:
17:34:01 ----------
17:34:01 ReminderBeep cannot be resolved to a type
17:34:01 ^^^^^^^^^^^^
17:34:01 new ReminderBeep(2);
17:34:01 2. ERROR in /tmp/jfxide/tmp/Strategy.java (at line 44)
17:34:01 ----------
17:34:01 Return type for the method is missing
17:34:01 ^^^^^^^^^^^^^^^^^^^^^^^^^
17:34:01 public ReminderBeep(int seconds) {
17:34:01 1. ERROR in /tmp/jfxide/tmp/Strategy.java (at line 27)
17:34:01 ----------


I guess it's something really simple I'm missing, nevertheless I kindly ask for help.


 
 Post subject: Re: Timer (do something every x seconds) Post rating: 0   New post Posted: Thu 21 Oct, 2010, 09:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,
we corrected your code:
   . . .
  @SuppressWarnings("unchecked")
  class ReminderBeep implements Callable{
          //This one look like constructor, so we putted in a inner class
          //This class implements callable interface, because this class must be lunched in a separate thread - not in a strategy's thread
     public ReminderBeep(int seconds) {
   
       timer = new Timer();
       timer.schedule(new RemindTask(), seconds*200);
     }

   @Override
   public Object call() throws Exception {
      return null;
   }
  }
   . . .
   //timer is called in a separate thread
   context.executeTask(new ReminderBeep(2));
    . . .

Please consider this https://www.dukascopy.com/wiki/index.php/Threading
If you still have a questions, please do not hesitate to ask


 

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