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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:57:41+00:00 2026-05-29T06:57:41+00:00

We are working on a project to handle virtual machine managers from a Java

  • 0

We are working on a project to handle virtual machine managers from a Java application.

At the moment, we faced a problem where some instructions must be considered as a task because they require more time. Theses taks can also end with errors or be a success, and we can’t know the result from the application unless we request the state of the task to the VM hypervisor.

To have a smooth application we wanted to have a CommandManager to handle the differents request to theses hypervisors in separated threads. The problem is that these Command might return specific errors such as that we used to catch in the view to display revelant information to the user but when we implement Runnableon our Commands interface, we can’t throw any exception out of that thread back to reach the view.

What could I do to keep notifying the user of the errors that happened and their nature?

Sorry for my english!

Lets see the code below for a brief example :

First the Command

class ChangeMemorySize extends Command {
    private String name;
    private int memorySizeMb;

    public ChangeMemorySize(Hypervisor hypervisor, String server,
            String name, int memory) {
        super(hypervisor, server);
        this.name = name;
        this.memorySizeMb = memory;
    }
    protected void execute() throws ConnectionException,OperationException{

    //Some code here

    }
    public void run() //CANT THROW ANYTHING HERE :throws VmConfigFault, 
        try{
            execute();
        }catch{Exception e){
            // I have to catch it all here!
        }

This isn’t real code this is just an example. This command would then be passed to a manager who would run it in another thread. But I loose all the specifics exception that I used to notify the user of what really happened in there!

  • 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-29T06:57:42+00:00Added an answer on May 29, 2026 at 6:57 am

    Use an ExecutorService and do one of two things.

    First you can store all results in a Future and when you want to know if an Exception occurs just invoke Future.get() and handle any exception.

    Second you can create the ExecutorService with a ThreadFactory in which you set it a knew UncaughtExceptionHandler like

           final UncaughtExceptionHandler handler = new UncaughtExceptionHandler() {
                public void uncaughtException(Thread t, Throwable e) {
                    // notify error
                }
            });
            Executor executor = Executors.newFixedThreadPool(1, new ThreadFactory() {
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setUncaughtExceptionHandler(handler);
                    return thread;
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're working in a Dynamic Data project that will handle entities coming from two
I'm working on a project and we want to handle our logging using log4j.
Backstory: I'm using log4net to handle all logging for a project I'm working on.
I working on project and have problem with threading and update of UI. I
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I'm working on project that lets users choose some scientific authors and columnists and
I am currently working on a project for school that is a java memo
I'm working on a project that calls a console window to process some data
I'm working on a project in Lightswitch and I'm trying to handle the keyup
I'm working on a project using Symfony 2, I've built a bundle to handle

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.