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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:20:55+00:00 2026-06-18T07:20:55+00:00

I recently had to complete one of these job interview coding exercises. Basically it

  • 0

I recently had to complete one of these job interview coding exercises. Basically it required implementing a message queue class that:

  • maintains items based on a priority field in the incoming message.
  • the message can be in one of three priority categories high, medium, low controlled via message.priorityField value range.
  • has a getSize and isEmpty methods.
  • has a place(message) method.
  • has a remove method.
  • has getFront() method (which returns highest priority message)

What I did in the end without going into too much detail is implement a MessageQueue class that internally uses ConcurrentSkipListMap (a concurrent and ordered map) to hold the messages.

I also implemented a basic JUnit test case that tests for basic business requirements.

Now as its a messaging queue and hence messages can come in concurrently of course I need to test the occurrent aspect of the implementation.

I’m getting closer to the heart of the question now.

My thinking is that the basic JUnit test case should verify the code works when a single thread is interacting with the implementation.

I then implemented a concurrent test case which should verify the occurrent aspect of the implementation.

Now here is the question:
What concurrent aspects should I be testing for?

The only thing I can think of is having multiple producer threads that inject methods in the queue and multiple consumer threads that remove the messages (via getFront()) .
What is being verified here is that whatever messages went in the queue will eventually come out.

But is that enough? what other concurrent aspects could be tested for here?

Also worth noting that I have already submitted the solution so whatever you suggested will not have any impact on my chances for this job I applied for.

  • 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-18T07:20:57+00:00Added an answer on June 18, 2026 at 7:20 am

    Testing for thread safety is a pain as you are basically trying to prove the correctness of your program for every eventual concurrent execution. There are a few ways to go about this:

    1. Formally prove the correctness of your program in the terms of the JMM. This will require you to discuss each explicit ‘happens-before’ edge in you program and how consistency is maintained based on those edges. This is possible for something as basic as a queue but becomes very complex the more functionality and edges are thrown in. I’d recommend you go through this process in any case and document your intentions/assumptions when writing concurrent code.

    2. Construct test cases which demonstrate intended above behaviour by using count down latches or other means of suspending threads of execution at specific points in your program to force contention. This may turn your code into a horrible mess if taken too far but can be a very helpful technique.

    3. Statistically demonstrate correctness by exercising the code over a sufficient period of time. This is the principle behind the concurrency torture suite used to verify JVM implementation correctness with regards to the JMM. This will require you to form expectations on legal/illegal states for participating threads and running your program for a long enough time on a machine with enough parallel threads. If you never hit an illegal state your program is correct :). If you run it for long enough without hitting an illegal state then in all probability you are correct.

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

Sidebar

Related Questions

I recently had a techical test for a job interview where I did a
I recently had an idea to create my own String class to make using
I recently had a complete new install of my (archlinux) System. For that reason
I recently had a problem when comparing two NSURLs and compare one NSURL with
I recently had an interview at a small company that wants to greatly increase
I recently had a class project where I had to make a program with
i recently had to do a test for a job, and i got feed
I recently had an interview where I was asked to connect to the companies
One unexpected issue I faced recently was that I had Sagepay payment gateway configured
I am currently pretty stumped on this one. I recently had to update my

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.