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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:10:49+00:00 2026-05-26T18:10:49+00:00

As title says, mock code to demostrate my problem Driver Class import java.io.*; public

  • 0

As title says, mock code to demostrate my problem

Driver Class

  import java.io.*;

    public class driver
    {

        public static void main(String[] args)
        {
            PipedWriter writer1 = new PipedWriter();
            PipedWriter writer2 = new PipedWriter();
            PipedReader reader1 = new PipedReader();
            PipedReader reader2 = new PipedReader();

            Thread thread1 = new MyThread(writer1, reader1);
            Thread thread2 = new MyThread(writer2, reader2);
            try
            {
                  writer2.connect(reader1);
             } catch(Exception e)
             {
                  e.printStackTrace();
             }
        }
    }

MyThread Class

 import java.io.*;
public class MyThread extends Thread
{
    PipedReader input = new PipedReader();
    PipedWriter output = new PipedWriter();

    public MyThread(PipedWriter input, PipedReader output)
    {
        try
        {
            this.input.connect(input);
            this.output.connect(output);
        } catch(Exception e)
        {
            e.printStackTrace();            
               }
    }
    public void run()
    {
        try
        {
            input.close();
            output.close();
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

I’m not sure if the .connect method is what I should be using. What I want to do is have the output stream coming from the first thread writing straight into the input stream of the second.

The code above compiles fine but says its already connected otherwise.

java.io.IOException: Already connected
        at java.io.PipedWriter.connect(Unknown Source)
        at driver.main(driver.java:17)
  • 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-26T18:10:49+00:00Added an answer on May 26, 2026 at 6:10 pm

    If a writer is connected to a reader, the reader is also connected to the writer. You don’t need to connect them twice. And if one thread writes and the other reads, you just need one writer and one reader.

    Create both in the main thread, connect them, then creat one thread with the reader and one with the writer, and start both threads.

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

Sidebar

Related Questions

As title says, how do I call a java class method from a jsp,
As the title says, will this code work and will it work in major
Title says mainly the problem. On my spare time for our group at school,
As the title says, is deploying/using applications through Java Web Start a viable option?
As the title says, I want to truncate user-input text string based on the
The title says everything. What is the CSS code to put shadows in the
As title says i whant to change my variables in java from my jruby
As the title says: What's best way of converting a string from any-case to
Exactly what the title says. Here's my connection string: \SQLEXPRESS;Database=GGDBase;Integrated Security=SSPI;Trusted_Connection=true;Persist Security Info=False; The
Title says what i'm trying to do. I can successfully generate an assembly if

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.