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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:51:14+00:00 2026-06-12T20:51:14+00:00

I have a worker processes working on a data queue. A training worker reads

  • 0

I have a worker processes working on a data queue. A training worker reads and processes data from the training queue. It continues to poll and on the look out for new data written to the queue.

I have implemented the worker as follows:

public static void main(String[] args) {
  startTraining()
}

public static boolean startTraining() {
  trainingWorker = new WorkerImpl(config);
  final Thread workerThread = new Thread(trainingWorker);

  WorkerListener listener = new WorkerListener() {
    public void onEvent(WorkerEvent event, Worker worker, String queue, Job job, 
                        Object runner, Object result, Exception ex) {
      if(event.equals(WorkerEvnet.JOB_SUCCESS) {
        //get data
        //process data
        //send data
      }
    }
  }

  trainingWorker.addListener(listener, WorkerEvent.JOB_SUCCESS, WorkerEvent.JOB_FAILURE,
                     WorkerEvent.WORKER_ERROR, WorkerEvent.WORKER_POLL);
  workerThread.start();
  workerThread.join();
}

I want unit tests to see if the worker read the data properly, processed it correctly and successfully sent it. The problem is because of Thread.join(); the call to the main function never returns (as the worker is suppose to run continuously). In this case should I not write unit tests for it? If yes, how can I write some other form of test that will ensure the worker is working as desired?

  • 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-06-12T20:51:16+00:00Added an answer on June 12, 2026 at 8:51 pm

    you may want either to remove join from your code, or to start new thread from your test case, which will start the worker for you.

    Obviously you will need the way to terminate the worker, for version it may look like

    public void stopWorker() {
     workerThread.interrupt()
    }
    

    so you will need to convert your workerThread local value to a field, and make it volatile.

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

Sidebar

Related Questions

I have a background worker thread that is constantly syncing data to/from a remote
I have a worker thread processing a queue of work items. work items might
I have a worker thread spawned from a GUI (for GUI performance), how do
I am working on a website that displays some data from DB that changes
I am working with information from big models, which means I have a lot
I have two (alternative) functions working on data supplied by a sensor. The functions
I am working on a Python backend web server that grabs realtime data from
I have a pool of worker processes (using multiprocessing.Pool ) and want to log
I have been working on implementing a (1) server, (n) worker role servers setup
I am currently working on a WPF application that processes data in a database

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.