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

  • Home
  • SEARCH
  • 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 3270718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:39:54+00:00 2026-05-17T18:39:54+00:00

Brief description of UI and setup 1)Plain vanilla frame, with button1 and button2 and

  • 0

Brief description of UI and setup

1)Plain vanilla frame, with button1 and button2 and textarea1 and textarea2

2)Button1 launches a continuous running task using a swingworker myswingworker1 and the swingworker’s process method continually updates textarea1

3)Button2 launches a continuous running task using a swingworker myswingworker2 and the swingworker’s process method continually updates textarea2

The continually running task in this case is “adb logcat”, this command keeps writing continuous log information to the outstream, that I capture and print to the textarea. this capturing and printing is done inside the swingworker.

Problem

Only one one button seems to do the intended task of printing the output to the textarea at a time, either button1 OR button2, whichever was started first. The UI never freezes though.

As a part of the experiment, I replaced one long running task with say a command “dir” which runs and return immediately, ie I attached “dir” to button2. Now if I run button2, it works and then button1 it works too. If I do the other way round only the long running task started by button1 runs and the task started by button2 seems to wait for the long running task to end, which defeats the whole purpose of using a swingworker.

How do solve this problem? How do I prevent my UI from waiting for one swingworker to finish?

code excerpt


public class multiswing extends javax.swing.JFrame {

public multiswing() {
    initComponents();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    myswingworker1 m1=new myswingworker1(jTextArea1);
    m1.execute();
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    myswingworker2 m2=new myswingworker2(jTextArea2);
    m2.execute();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new multiswing().setVisible(true);
        }
    });
}


public class myswingworker1 extends SwingWorker {

JTextArea jTextArea = new JTextArea();
Process proc;
Runtime rt = Runtime.getRuntime();

public myswingworker1(JTextArea jTextArea) {
    this.jTextArea = jTextArea;
}

protected Void doInBackground() throws Exception {

    String line = null;
    rt = Runtime.getRuntime();
    proc = rt.exec("adb logcat");
    InputStream stdin = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stdin);
    BufferedReader br = new BufferedReader(isr);
    while ((line = br.readLine()) != null) {
        publish(line);
    }

    return null;
}

@Override
protected void process(List<String> chunks) {
    String data = chunks.get(0);
    jTextArea.append(data + "\n");
}

}


public class myswingworker2 extends SwingWorker {

JTextArea jTextArea = new JTextArea();
Process proc;
Runtime rt = Runtime.getRuntime();

public myswingworker2(JTextArea jTextArea) {
    this.jTextArea = jTextArea;
}

@Override
protected Void doInBackground() throws Exception {

    String line = null;
    rt = Runtime.getRuntime();        
    proc = rt.exec("dir");
    InputStream stdin = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stdin);
    BufferedReader br = new BufferedReader(isr);
    while ((line = br.readLine()) != null) {
        publish(line);
    }

    return null;
}

@Override
protected void process(List<String> chunks) {
    String data = chunks.get(0);
    jTextArea.append(data + "\n");
}

}

  • 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-17T18:39:54+00:00Added an answer on May 17, 2026 at 6:39 pm

    This helped me

    http://forums.sun.com/thread.jspa?threadID=5434659

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

Sidebar

Related Questions

Uhm I'm not sure if anyone has encountered this problem a brief description is
In brief: Is it ever excusable to have assembly names and class names stored
I happened upon a brief discussion recently on another site about C# runtime compilation
Could somebody give me a brief overview of the differences between HTTP 1.0 and
I'll try to be brief. What is the best practice for calling a routine
Let's put Heisenberg aside for a brief moment. How would I go about to,
I'm going to be brief because I'm short on time, so I apologize if
The question, in brief: In MVC, how do you distinguish between a checkbox click
Basically, I would like a brief explanation of how I can access a SQL
Guys, can someone give me a brief run through of how to change the

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.