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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:32:38+00:00 2026-05-27T05:32:38+00:00

The assignment is to implement a very very simplified computing cloud. The cloud instances

  • 0

The assignment is to implement a very very simplified computing “cloud”. The cloud instances (“engines”) are supposed to regularly send keep-alive messages (“commands”) to a supervisor. I’ve implemented this using the following task:

public class KeepAlive implements Runnable {
    Engine engine;
    DatagramSocket sock;

    public KeepAlive(Engine engine) {
        this.engine = engine;
        sock = new DatagramSocket();
    }

    public void run() {
        DatagramSocket sock = null;

        EngineArguments args = engine.getArgs();

        KeepAliveCommand cmd = new KeepAliveCommand(…);
        byte[] data = cmd.toString().getBytes("UTF-8");
        DatagramPacket p = new DatagramPacket(data, data.length, InetAddress.getByName(args.getSchedulerHost()), args.getSchedulerPort());
        sock.send(p);
    }    
}

that is scheduled for execution using scheduleAtFixedRate(). I’m doing a graceful (ish) shutdown of using shutdownNow() to avoid having to keep explicit references to long-running tasks.

Is there any “clean” way to perform cleanup specific to the task (closing the DatagramSocket)? Alternately, does it even make sense to keep a DatagramSocket instance between scheduled runs or can I just create a new one every time?

  • 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-27T05:32:38+00:00Added an answer on May 27, 2026 at 5:32 am

    As I see it, you have 2 options:

    1. Keep track of the sockets within a “Socket Pool” and using a “send” method of this pool.
      Then, after you shutdown the executor you shutdown the Pool
    2. Extend ScheduledThreadPoolExecutor, which can be a little more difficult. But, the API is clean… Notice that you can “decorate” the tasks, also there is a “termintated” method.

    I like the idea of the “socket pool”. Then, how the connection are handled is up to the pool (i.e. if you have a persistent connection or you create one per request)

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

Sidebar

Related Questions

For an assignment, we had to implement something like a very basic sexp parser,
So for my assignment, I am supposed to implement a Node class that just
For my theory of computing languages class, we got a homework assignment to implement
I have an assignment that I'm supposed to implement the MIPS processor in C++
What is the proper way to implement assignment by value for a reference type?
For the new computer science assignment we are to implement a list/array using an
The assignment at my first year uni computing course says my program should read
I have an assignment to implement my own version of Collections.fill() and Collections.reverse(). The
So I'm trying to implement a cache in C. I have included a very
My assignment is to implement a multithreaded web server in Java but i have

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.