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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:31:19+00:00 2026-05-14T02:31:19+00:00

Greetings, coders, Background Info and Code I am trying to create a daemon-type program

  • 0

Greetings, coders,

Background Info and Code

I am trying to create a daemon-type program (e.g., it runs constantly, polling for things to do) that is managed by a GWT application (servlets in a WAR) which is in turn served by an embedded Jetty server (using a WebAppContext). I’m having problems making the GWT application aware of the daemon object.

For testing things, I currently have two projects: The daemon and embedded Jetty server in one (EmbJetTest), and the GWT application in another (DefaultApp). This is the current state of the code:

First, EmbJetTest creates an embedded Jetty server like so, using a ServletContextListener to inject the daemon object into the web application context:

    EmbJetTest.server = new Server(8080);

    // Create and start the daemon
    Daemon daemon = new Daemon();
    Thread thread = new Thread(daemon);
    thread.start();

    // war handler
    WebAppContext waContext = new WebAppContext();
    waContext.setContextPath("/webapp");
    waContext.setWar("./apps/DefaultApp.war");
    waContext.addEventListener(new DaemonLoader(daemon));

    // Add it to the server
    EmbJetTest.server.setHandler(waContext);

    EmbJetTest.server.setThreadPool(new QueuedThreadPool(10));

    // Start the server; join() blocks until we shut down
    EmbJetTest.server.start();
    EmbJetTest.server.join();

    // Stop the daemon thread
    daemon.stopLoop();

Daemon is a very simple object with a couple properties, at the moment. DaemonLoader is the following ServletContextListener implementation:

private Daemon daemon;

public DaemonLoader(Daemon daemon)
{
    this.daemon = daemon;
}

@Override
public void contextDestroyed(ServletContextEvent arg0) {

}

@Override
public void contextInitialized(ServletContextEvent arg0) {
    arg0.getServletContext().setAttribute("daemon", this.daemon);
}

Then, in one of my servlets in the GWT application, I have the following code:

Daemon daemon = (Daemon) this.getServletContext().getAttribute("daemon");

However, when I visit localhost:8080/webapp/* and invoke the servlet, this code throws a ClassCastException, even though the classes are of the same type. This StackOverflow answer indicates that this is because the two classes are loaded with different classloaders.

Question

My question is twofold.

  1. Am I even on the right track here? Am I going about this completely the wrong way? Something tells me I am, but I can’t think of another way to make the daemon available to both applications. Is there a better way to communicate with the daemon from the GWT application? Should the GWT app own the daemon and somehow start the daemon itself? The daemon needs to run even if no one visits the one of the GWT app’s servlets–how could I do this?
  2. If I am on the right track, how can I get around the classloader issue?

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-05-14T02:31:20+00:00Added an answer on May 14, 2026 at 2:31 am

    Why not just run the functionality of the daemon in a separate thread within the GWT web application ? That way you’ll avoid all the classloading grief (as you’ve found out, apps in different .war files run within their own classloaders).

    Just create a servlet for your daemon alongside your existing servlets (in the same .war), and start/stop the thread on servlet initialisation and destruction.

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

Sidebar

Related Questions

Greetings, fellow coders! I have this table that contains categories and subcategories (actually I
Greetings Overflowers, Is there an SQL DBMS that allows me to create an indexed
Greetings Stack Overflow community. I'm trying to make a function that can pop all
Greetings! I am trying to check directory write-permissions from within a Windows MFC/ATL program
Greetings, The VBA code below will create an Excel QueryTable object and display it
Greetings everyone and thank you for checking out my post. I am trying to
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings, I am trying to learn pointers in C, I simply want my addtwo
Greetings, Trying to sort through the best way to provide access to my Entity
Greetings! I'm trying to have a UIWebView controlled from generated events. Is there a

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.