Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 983805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:54:57+00:00 2026-05-16T04:54:57+00:00

I am trying to do a bit of asynchronous programming, but my Java skills

  • 0

I am trying to do a bit of asynchronous programming, but my Java skills are a bit rusty…

Here’s my code:

   private static String uname="xxx";
   private static String pword="xxx";
   private static int productId=82; 
   private static String sessionToken="";

    public static void main(String[] args)
        {
            BFGlobalService_Service service=new BFGlobalService_Service();
            BFGlobalService betfair=service.getBFGlobalService();

            System.out.println("hello");

            LoginReq loginReq=new LoginReq();
            loginReq.setUsername(uname);
            loginReq.setPassword(pword);
            loginReq.setProductId(productId);
            loginReq.setLocationId(0);
            loginReq.setVendorSoftwareId(0);

            LoginResp loginResp=new LoginResp();
            loginResp=betfair.login(loginReq);   //this line is very slow ;(
            sessionToken=loginResp.getHeader().getSessionToken();

            ...
        }

The line “loginResp=betfair.login(loginReq)” takes time (I have a very slow 3G network) and holds up the whole program flow. Can I raise an event when this completes?

i.e. I’d like this kind of event handler pseudocode:

private void handleNewLoginResp(...)
{
   System.out.println("login response received");
   sessionToken=loginResp.getHeader().getSessionToken();
}

I’m hoping this will be straightforward enough! I’ve tried googling, but all I can find is articles on GUIs, etc.enter code here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:54:58+00:00Added an answer on May 16, 2026 at 4:54 am

    Read up on Java Concurrency. Assuming you have a UI, you’ll want to use SwingWorker, or whatever is functional equivalent for your environment.

    Update:

    The only part that might trip you up is that a listener will be called on the background thread’s context, not the main thread’s. So, you will need to use synchronize blocks to ensure objects created on the background thread are flushed from the thread’s cache to common memory.

    It’s no different than writing custom event handling for the GUI. (Which is why you’re not finding anything when you search.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do bit reversal in a byte. I use the code
Trying to understand Ruby a bit better, I ran into this code surfing the
I'm using ubuntu 64-bit and trying to run a .asm file on NASM. But
I'm running into a bit of problem when trying to readToEnd from an asynchronous
I'm running into a bit of problem when trying to post data asynchronously. Here's
I'm a bit stuck trying to get my code to output correctly, see below.
http://pastebin.com/x5UnA1sE Here's a paste of a bit of my troubled coded. I'm trying to
I am a bit of a n00b with memory allocation, but I am trying
I'm currently struggling a bit trying to keep my controller specs DRY and succinct
I am going a bit nuts trying to figure out why the following won't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.