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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:50:27+00:00 2026-05-26T14:50:27+00:00

I’m creating an XML-RPC server in Java using the Redstone XML-RPC library . The

  • 0

I’m creating an XML-RPC server in Java using the Redstone XML-RPC library. The server is responsible for kicking off commands on the system and then shooting back the response. For example, the user tells the server to do a ls and the server returns a listing of files. Similarly, the user can do asynchronous commands and get back a process ID to query with later. All these methods are under one big subclass of Command which is part of the main class RPCServlet extends XmlRpcServlet.

In order to accomplish this, I’m keeping a global HashMap of instances. When an async command comes in, I create an instance of class ProcessManager which extends thread. I then add it to the instances hash, run it, and return back the ID to the user. When a query for that ID comes in, I look it up in the global hash, and return either its full or partial status (depending on whether or not it’s completed).

This works OK when it’s just one request after another, but when you really begin to pound it with lots of requests that operate on the global hash instances, it gets concurrency exceptions.

Now here are my points of confusion:

  • When a request comes in, does a new object of class Command get created or is it one object sitting there forever taking in commands? Following on that, how does each request see the global hash of instances? This is my init code

    public class RPCServlet extends XmlRpcServlet {

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);  
        getXmlRpcServer().addInvocationHandler("Command", new Command(instances));  
    }
    

    }

  • When I attempt to solve the concurrency exception issue, I use syncronized OR ConcurrentHashMap rather than HashMap. Either way, I run into deadlock this way. Why might this be?

  • Where should my global HashMap of instances go? In RPCServlet? its subclass Command?

Here’s how I run into these concurrency exceptions:

  1. I create a bunch of async commands and then attempt to kill them all
  2. I start lots of different clients all doing this, and it’ll inevitably run into a concurrent exception.

Here is what the asyncCmd looks like:

public HashMap asyncCmd(XmlRpcStruct struct) throws XmlRpcFault {
            HashMap hash;
            if (struct.containsKey("command")) {
                ProcessManager proc = new ProcessManager(struct);
                boolean validInput = proc.readInHashValues();
                if (!validInput) {
                    throw new XmlRpcFault(400, proc.procResult.getTopError());
                }
                int id = proc.objectId;

                instances.put(id, proc);

                proc.start();
                String a;
                if ((a = proc.procResult.getTopError()) != null) {
                    throw new XmlRpcFault(500, a);
                }

                hash = new HashMap();
                hash.put("id", id);
                return hash;
            } else {
                throw new XmlRpcFault(400, "Unable to find a command");
            }
        }

KillAll:

public HashMap killAll() throws XmlRpcFault {
            HashMap retHash = new HashMap();

            int length = instances.values().size();
            if (length > 0) {
                Set keys = instances.keySet();
                for (Object key : keys) {
                    retHash.put(key, killAllKiller(Integer.parseInt(key.toString())));
                }
                //Since we killed all procs, suggest a GC as well
                instances.clear();
                System.gc();


                return retHash;
            } else {
                throw new XmlRpcFault(404, "No processes running");
            }

        }
  • 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-26T14:50:28+00:00Added an answer on May 26, 2026 at 2:50 pm

    Let me suggest another alternative

    • Upon receiving the request, put the command and an id into a Queue (wrap in an object), and return the id into the user
    • Create a ThreadPoolExecutor that will receive the commands from the queue, execute them and put the results in an ConcurrentHashMap
    • The clients will then access only the results map

    In this way, there will not be a contention between new requests and results.

    I would put this map in the servlet context, which the natural place to keep application level variables.

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an XML file, the creators of it stuck in a bunch social

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.