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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:02+00:00 2026-05-25T03:20:02+00:00

I wrote an app that implements a web server with multithreading. The main activity

  • 0

I wrote an app that implements a web server with multithreading.
The main activity has a button to start/stop a thread. When the server is powered on, this thread stays in listening and, if there is a request it creates a new thread to serve it.
The app works fine, but now I would use a service instead, so it can work in background.

Actually I’ve this design (semplified):

WebServer.java

class WebServer implements Runnable{
protected Thread t;

 public void start(){
  ON=true;
  t=new Thread(this,"WebServer");
  t.start();
 }

 public void stop(){
 ON=false;
 t=null;}

 public void run(){
 while(ON)
 ...
 }

 public isOn(){
  return ON;
 }
}

DroidServer.java

class DroidServer extends WebServer{
...
}

MyActivity.java

public class MyActivity extends Activity{
ws = new DroidServer(8080,this);
btn.setOnClickListener(new OnClickListener(){
 public void onClick(View V){
    if(!ws.isOn()){
     ws.start();
     btn.setText("Stop");
    }else{
     ws.stop();
     btn.setText("Start");
    }}});
}

What should I change, to make it use Services? I’d like to extends Service from DroidServer, but this class already extends WebServer… any solutions?

  • 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-25T03:20:03+00:00Added an answer on May 25, 2026 at 3:20 am

    Service is not a replacement for a Thread.
    Per definition from Service :

    Most confusion about the Service class actually revolves around what
    it is not:

    • A Service is not a separate process. The Service object itself
      does not imply it is running in its own process; unless otherwise
      specified, it runs in the same process as the application it is part
      of.
    • A Service is not a thread. It is not a means itself to do work off
      of the main thread (to avoid Application Not Responding errors).

    What you should do it create a Service then have your DroidServer run in the Service as a separate Thread so it could accept request in the background

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

Sidebar

Related Questions

I am designing a web app that has some information that needs to be
A while ago I wrote an app that relied on XML coming out of
I wrote a C app that uses the PCRE library. Everything works on my
I wrote a small app that turns out to be using a lot of
i wrote a java app that communicates and stores data in oracle; my question
I wrote a simple Sinatra app that generate an image using rmagick from some
I have a simple Google App Engine app, that I wrote using ordinary strings.
I'm writing a web app that at one point allows a user to upload
I'm working on a web app in ASP.NET 2.0 that involves serving images via
I wrote a simple web app to let user input data as they walk

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.