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 8007849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:57:29+00:00 2026-06-04T17:57:29+00:00

Following is my main class. public class ShareData { /** * @param args */

  • 0

Following is my main class.

public class ShareData {

    /**
     * @param args
     */
    public static void main(String[] args) {
        ShareReader aShareReader = new ShareReader("http://test.com:9000", "dilip.id@gmail.com", "password");
        Thread fileThread = new Thread(aShareReader);
        fileThread.run(); // fileThread.start() not calling the run() method
    }
}

If I type fileThread.run() run method is called. If I call fileThread.start() the run metod is not called. Following is my thread class. I dont know what I am doing wrong.

public class ShareReader implements Runnable {

    private String itsShareURL =    null;
    private String itsUserId        =   null;
    private String itsPassword      =   null;
    private String itsAuthToken     =   null;
    private String itsLoginURL      =   null;
    private String itsChannelUpateURL   =   null;


    /**
     * 
     */
    public ShareReader(String theShareURL, String theUserId, String thePassword) {
        this.itsShareURL    =   theShareURL;
        this.itsUserId          =   theUserId;
        this.itsPassword        =   thePassword;
        this.itsLoginURL        =   itsShareURL + "/v1.0-SNAPSHOT/login";
        this.itsChannelUpateURL =   itsShareURL + "/v1.0-SNAPSHOT/updateChannelSubscription/";
    }

    public void run() {
        JSONObject json;
        JSONArray jsonArray;
itsAuthToken = getToken(itsUserId, itsPassword);
    updateChannelList(itsAuthToken);

    String aURL = "http://test.com:9000/v1.0-SNAPSHOT/userTimeline/"+itsAuthToken+"/";
    try {
        String lat = null;
        String lon = null;
        String udid = null;
        String dateTime =  null;
        String eventID = null;
        aEventBean = new EventBean();
        jsonArray = readJsonArrayFromUrl(aURL);
        for (int i = 0; i < jsonArray.length(); i++) {
            json = jsonArray.getJSONObject(i);
            lat = json.getString("lat");
            lon = json.getString("lon");
            udid = json.getString("udid");
            eventID = json.getString("eventId");
            dateTime = json.getString("dateTime");
            aEventBean.setItsLatitude(lat);
            aEventBean.setItsLongitude(lon);
            aEventBean.setItsUDID(udid);
            aEventBean.setItsEventIdentifier(eventID);
            aEventBean.setItsDateTime(dateTime);
            System.out.println(udid + " ---> " +lat + " ==== " + lon);
            sendData(aEventBean);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block

        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
}
}

Sorry If I ask so basic question..
Ideally I need to do fileThread.start() to start a thread..
Thanks in advance…

  • 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-06-04T17:57:30+00:00Added an answer on June 4, 2026 at 5:57 pm

    run() is definitely called if you call start() on fileThread. Check your implementation of run()– its very likely that this method completes or terminates before your check for the print statements. Just an fyi, fileThread.run() is a sequential call while fileThread.start() is a parallel call.

    Another vague possibility is that you’re not implementing Java’s runnable; instead, that may be some custom Runnable class in your project.

    EDIT:

    So apparently calling fileThread.join() helped you fix your problem, but why does this work? If you call fileThread.join(), the main thread waits until the target (in this case, your fileThread object) terminates.

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

Sidebar

Related Questions

Considering following code public class A { public static void main(String[] args) { new
I have following code public class TEST { public static void main(String arg[]){ try
The following code works perfectly. public class StaticClass { public static void main(String[] args)
I have the following code: class Program { static void Main(string[] args) { new
Why is it that the following code: class swi { public static void main(String[]
My Java class contains the following methods: public static void main(String[] argv) //start the
I am trying to do the following: class Program { static void Main(string[] args)
Given the following code : import java.io.*; public class Main { public static void
I know why the following code doesn't compile: public class Main { public static
Let's assume I have the following code: public class MainClass { public static void

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.