This project has moved and is read-only. For the latest updates, please go here.

Thread and Subscriptions

Jan 9, 2014 at 2:39 AM
Edited Jan 9, 2014 at 3:45 AM
Hi robinson,

I hope you are doing well!

In your emulator project, I specifically took a look at the Session class. I'm just wondering why you made a class extends Thread (private class MarketSimulatorTypeClass extends java.lang.Thread), but you didn't really create a thread by calling in the startAsync( ) function? Could you please tell me what the actual purpose of that is?

And also, the way you open the service for subscriptions is quite a bit different from what the API does since I don't see any "//blp/mktdata" service in the RunMarketDataSubscription class. Everything is awesome, but only that one I have concerns about. Have you thought of changing it to be the same as the API?

Just so you know, I'm right now a student, and I'm really curious what kind of applications we can make using the Bloomberg Open API and what we can do with their databases. Could you please share some of your experience or point out some references so that it can be more realistic to me?

Thank you so much!
Danh Nguyen
Jan 9, 2014 at 7:50 PM

1) I don't think I understand your first question. In bemu/src/main/java/com/bemu/BEmu/ in startAsync() at line 180, I have a call to; This is the second last line in the startAsync function. The full function I have is this:
public boolean startAsync() throws Exception
    this._sessionState = SessionStateType.started;

    Event.EventType evttSession = new Event.EventType(Event.EventType.Constants.SESSION_STATUS);
    Event.EventType evttService = new Event.EventType(Event.EventType.Constants.SERVICE_STATUS);
    EventMarket evtSessionStatus = new EventMarket(evttSession, null, null);
    EventMarket evtServiceStatus = new EventMarket(evttService, new CorrelationID(), null);

    if (this._asyncHandler != null)
        this._asyncHandler.processEvent(evtSessionStatus, this);
        this._asyncHandler.processEvent(evtServiceStatus, this);
    return true;
Do you see any of this? What is the startAsync() function that you see?

2) I haven't noticed that before. The example code in my C# version uses //blp/mktdata but I must have made a copy-and-paste error in my Java code. Strangely, it looks like the code works in either case with the actual Bloomberg API. That's why I haven't noticed this in my testing. It looks like I can use either //blp/mktdata or //blp/refdata to make market data subscriptions. That's surprising. Regardless, I will change the Java code market data example to use.

Thanks again for your help. I appreciate it.

Jan 9, 2014 at 10:12 PM
Edited Jan 10, 2014 at 12:40 AM
Hi Jordan,

Sorry for not being clear in the 1st question. I meant the command will not create a thread. It simply just calls the run( ) function in the class MarketSimulatorTypeClass. Please correct if I'm wrong. To what I know, a thread will be created only when we call
If we use, then everything is still running on the Java main thread.

Thank you so much, Jordan!

Danh Nguyen
Jan 10, 2014 at 7:51 PM

I got it now. You're right, I should have been using this._marketSimulatorTypeClass.start();. This shows my unfamiliarity with Java. The code seems to function the same way using start().

I will put this edit in with the next version of my code. Thanks for spotting this and please let me know if you find any other peculiarities.

Jan 10, 2014 at 8:17 PM
Thank you Jordan,

Please let me know when the new version comes out!
I'm looking forward to hearing from you.

Have a good weekend!
Danh Nguyen
Jan 27, 2014 at 8:09 PM

FYI, I just released a new version today. Among other updates, I included your .start() change and credited you in the Git comments. Thanks again.