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

  • Home
  • SEARCH
  • 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 7903131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:40:09+00:00 2026-06-03T09:40:09+00:00

In my application I have two threads (I’m using AsyncTask class). in doInBackground() method

  • 0

In my application I have two threads (I’m using AsyncTask class). in doInBackground() method of each thread i’m calling my own getNewsItems(Url url) method, this method will connect to server and get response. after that in onPostExecute() method of each thread, i’ll call displayData() method to show results on screen.

The problem is when i run, the application crashes. I think its because these two thread have access to common methods in same time because when i separate common methods then the app runs successfully. I have no idea is it because of don’t use of serialization?

Thanks

  • 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-03T09:40:10+00:00Added an answer on June 3, 2026 at 9:40 am

    you can put a synchronized modifier to your method that is accessed by multiple threads.

    e.g.

    public synchronized void getNewsItems(Url url){
        //some logic here
    }
    

    so that, When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.

    you can also read about it here: http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html

    UPDATE:

    you can have the getNewsItems(Url url) in a separate class like this:

    public class NewsItems{
      getNewsItems(Url url){
        //some logic here
      }
    }
    

    and then instantiate it within your threads like this:

    public void run(){
      NewsItems ni = new NewsItems();
      ni.getNewsItems(url);
    }
    

    this way, same method will be called but in different class instances…

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

Sidebar

Related Questions

I have two threads in an Android application, one is the view thread, and
I have an application that has two threads. The first one (the main thread)
In my application I have two threads a main thread which is busy most
In my sample application, I have basically two threads. The main thread contains a
I have app that uses two threads: one thread for regular application work and
I have two threads, communicating with each other; each thread employs 'while(1) ..'. Now
I am profiling a C# application and it looks like two threads each calling
In my application I have two threads. Thread 1 is transferring data to Thread
I'm working on an image processing application where I have two threads on top
I have two application that need to talk to each other. App1 needs to

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.