below is some skeleton code from 3 classes.
Upon monitoring the threads in debug mode, when I call client.stopStrategy(SprocessId);
the strategy stops. however all the listener threads remain open. I would like all threads which started through the "AccountDesk" class to stop. I have unsuccessfully tried thread.stop(), interrupt, etc.. the call loop exists, however the listener threads remain active.
Here is the theory behind what I am trying to accomplish. Say I have multiple accounts which would be trading the same set of trades coming from a Database. My main application which is always running, should be able to start and stop accounts at any given time.
at this point I am down to a solution which is not acceptable. have my main app call a new JVM from the command line for each individual account, and then use system.exit() in each account.
please help implement my original plan.
Thank you
**************************************************
//main CLASS
new Thread(new AccountDesk().start();
**************************************************
//AccountDesk
public class AccountDesk implements Runnable{
private String jnlpUrl="https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
private String userName="ghghh";
private String password="ghghghg";
private IClient client;
private Instrument instrument;
private Long SprocessId;
private int AccountID=1;
public void run() {
try {
client= ClientFactory.getDefaultInstance();
SetListener();
Set<Instrument> instruments = new HashSet<Instrument>();
instruments.add(Instrument.valueOf("EURUSD"));
client.setSubscribedInstruments(instruments);
client.startStrategy(new AccountStrategy(AccountID));
}
catch (Exception e) {
}
try {
while (Thread.currentThread().isAlive()) {
Thread.sleep(1000);
//DATABASE DRIVEN FLAG TO QUIT
if(!AccountRS.getBoolean("ROBOT_ACTIVE")){
client.stopStrategy(SprocessId);
break;
}
}
}
catch (InterruptedException e){}
catch (Exception e) {
}
}
private void SetListener(){
client.setSystemListener(new ISystemListener() {
private int lightReconnects = 3;
@Override
public void onStart(long processId) {
SprocessId=processId;
}
@Override
public void onStop(long processId) {
}
@Override
public void onConnect() {
lightReconnects = 3;
}
@Override
public void onDisconnect() {
if (lightReconnects > 0) {
client.reconnect();
--lightReconnects;
}
else {
try {
Thread.sleep(10000);
}
catch (InterruptedException e) {
}
try {
client.connect(jnlpUrl, userName, password);
}
catch (Exception e) {
}
}
}
});
}
}
**************************************************
//AccountStrategy
public class AccountStrategy implements IStrategy {
private int AccountID;
public AccountStrategy(int ID){AccountID=ID;}
public void onStart(IContext context) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
}
public void onMessage(IMessage message) throws JFException {
}
public void onAccount(IAccount account) throws JFException {
}
}