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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:07:07+00:00 2026-06-14T03:07:07+00:00

I have developed a solution for Readers-Writers problem using thread. I have one monitor

  • 0

I have developed a solution for Readers-Writers problem using thread.

I have one monitor class and one Reader and one Writer class.Reader and writer class extend thread.

Now I am testing the code like this:

public static void main(String[] args) {

  ReadersWriters controller = new ReadersWriters();
  Reader r0=new Reader(controller);
  Reader r1=new Reader(controller);
  Reader r2=new Reader(controller);
  Reader r3=new Reader(controller);
  Writer w0=new Writer(controller);
  Writer w1=new Writer(controller);
  Writer w2=new Writer(controller);
  Writer w3=new Writer(controller);
  r0.run();
  w0.run();
  r2.run();
  r3.run();
  r1.run();
  r3.run();
  r2.run();
  w2.run();
  r1.run();
  w1.run();
  w3.run();
 }

And the output which I am getting is this:

Reader number 0 arrives
Reader number 0 starts to read
Reader number 0 finishes reading
Writer number 0 arrives
Writer number 0 starts to write
Writer number 0 finishes writing
Reader number 2 arrives
Reader number 2 starts to read
Reader number 2 finishes reading

…and so on.
The problem here is that I am unable to test the concurrency.Because it looks like my main program is calling Reader or writer one by one,which is not the kind of testing I am trying to achieve.

Can anyone help me please.Please feel free to ask any clarification you might need.

  • 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-14T03:07:08+00:00Added an answer on June 14, 2026 at 3:07 am

    It looks like you’ve implemented a Runnable, but not wrapped it in a thread. I suspect you’re calling run() on your Runnable, rather than start() on a thread. Check the tutorial section on defining/starting a thread.

    You can’t reliably test multi-threaded code in unit tests and the like. It could work one time, or many times, and only fail once in a million test cases (or immediately in production). I would favour thread-safe coding techniques (e.g. writing immutable objects), static code analysis tools (e.g. PMD), and perhaps code reviews if you’re unsure.

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

Sidebar

Related Questions

We have an ASP.Net MVC 1.0 solution developed using Visual Studio 2008 and .net
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
Actually we have developed one mobile solution, which is used by our customers. But
I am using SharePoint 2010 and I have developed a SharePoint 2010 solution which
I have developed 2 mobile apps using PhoneGap. One is a free ad supported
We currently have a solution developed using SSIS / C#. The SSIS package (amongst
I have developed a solution in Visual Studio 2008 C# WPF! I'm using a
I have developed one application for sending mail using vb.net. for that i'm using
I'm very newbie to Ubuntu OS and I have my solution developed in visual
I have a solution consisting of about 10 important DLL files which are developed

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.