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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:54:40+00:00 2026-06-04T13:54:40+00:00

I have a Service in my app (created by a thread), and inside I

  • 0

I have a Service in my app (created by a thread), and inside I create another thread and that is a TCP server.
Short time after starting the thread (and fully working, receiving and handling the packages received) the service is killed by “timeout executing service” and ANR in my service.

This is the code of my Service and the thread that is doing all the work:

public class Android_Wifi_Service extends Service {

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        handleStart();
        return START_STICKY;
    }

    private void handleStart() {
        Server server=new Server(this);
        new Thread(server).run();
    }


    @Override
    public void onDestroy(){
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

}

And this is my thread:

public class Server implements Runnable {
    private boolean end=false;
    private Context context;

    public Server(Context _context){
        this.context=_context;
    }

    @Override
    public void run() {
        try {
            ServerSocket ss= new ServerSocket(5552);

            while(!end){
                //wait for connection
                System.out.println("Server Waiting connection");
                Socket s=ss.accept();
                SenderMessage msg=null;
                // connected 
                InputStream is = s.getInputStream();
                ObjectInputStream obj=new ObjectInputStream(is);
                try {
                    msg= ( SenderMessage ) obj.readObject();
                } catch (Exception e) {
                    Log.e("Message Receive Error", e.toString());
                }
                obj.close();
                is.close();
                s.close();
                if(msg!=null){
                    // do somethings
                }
            }

        } catch (IOException e) {
            Log.e("Messages Server", e.toString());
        }

    }   
}

And this is the logcat:

> 05-26 13:48:39.019: W/ActivityManager(1364): Timeout executing
> service: ServiceRecord{407b1838
> wifi/.auxiliar.Android_Wifi_Service} 05-26
> 13:48:39.179: I/Process(1364): Sending signal. PID: 4129 SIG: 3 05-26
> 13:48:39.179: I/dalvikvm(4129): threadid=4: reacting to signal 3 05-26
> 13:48:39.219: I/dalvikvm(4129): Wrote stack traces to
> '/data/anr/traces.txt' 05-26 13:48:39.229: I/Process(1364): Sending
> signal. PID: 1364 SIG: 3 05-26 13:48:39.229: I/dalvikvm(1364):
> threadid=4: reacting to signal 3 05-26 13:48:39.329: I/dalvikvm(1364):
> Wrote stack traces to '/data/anr/traces.txt' 05-26 13:48:39.339:
> I/Process(1364): Sending signal. PID: 1452 SIG: 3 05-26 13:48:39.339:
> I/dalvikvm(1452): threadid=4: reacting to signal 3 05-26 13:48:39.379:
> I/dalvikvm(1452): Wrote stack traces to '/data/anr/traces.txt' 05-26
> 13:48:39.389: I/Process(1364): Sending signal. PID: 1433 SIG: 3 05-26
> 13:48:39.389: I/dalvikvm(1433): threadid=4: reacting to signal 3 05-26
> 13:48:39.419: I/dalvikvm(1433): Wrote stack traces to
> '/data/anr/traces.txt' 05-26 13:48:39.919: D/dalvikvm(1364):
> GC_CONCURRENT freed 1086K, 42% free 5485K/9351K, external 1223K/1735K,
> paused 7ms+12ms 05-26 13:48:40.089: D/dalvikvm(1364): GC_EXPLICIT
> freed 116K, 41% free 5529K/9351K, external 1223K/1735K, paused 108ms
> 05-26 13:48:40.829: E/ActivityManager(1364): ANR in
> wifi:Service 05-26 13:48:40.829:
> E/ActivityManager(1364): Reason: Executing service
> wifi/.auxiliar.Android_Wifi_Service

Can anyone help me?

  • 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-04T13:54:42+00:00Added an answer on June 4, 2026 at 1:54 pm

    You do not start a Thread by calling run(). You start a Thread by calling start(). Right now, you are simply calling your own Thread‘s run() method on the main application thread.

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

Sidebar

Related Questions

I have created a service class for my network connection so that my app
I have created a .Net application to run on an App Server that gets
I have a web service app, I have 1 web service call that could
I have a service monitor app that monitors the status of three other servers
I have a WCF client/service app that relies on secure communication between two machines
I have a windows service that has it's name set by an app.config. I
I am trying to create an android app that communicates with a local server
I have created a web-service app and i want to populate my view controllers
I have created a test service with a method that contains a very long
I have a Winform app that has a backgroundWorker thread and does all operations

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.