pls help Inter thread communication

Search Forum

Popular Topics

Converting String to Clob

need an idea

Use ReturnValue from C...

password refresh problem

how to replace characters in...

Forum Home > Java Programming

Topic: please go through the code

Duke Dollars

4 Duke Dollars assigned to this topic. Transfer more points to this topic, or reward the best messages with points using the icons below.

Welcome jeevankc!

You are not watching this topic.

This topic has 0 replies on 1 page (Most recent message: Aug 15, 2001 9:19 PM)

Author: jeevankc Aug 15, 2001 9:19 PM

i have an problem with interthread communication see the code below:

Two threads are independent thread and i would like to access the variable from another thread.

I have written two thread class one will keep on update the vector table and sleep for a specified time. And another class has to get the vector variable and get the message from the buffer and put it to the file and delete all the message from the buffer. If any one know the interthread communication pls do correct the programme urgent. bye

import java.io.*;

import java.util.*;

import java.lang.reflect.*;

class AddVector extends Thread

{

Vector buffer = new Vector();

ThreadGroup threadGroup;

String str;

String refNo = new String();

String message = new String();

String api_Name = new String();

String station_Name = new String();

String status = new String();

String date_Time = new String();

String token = new String();

public AddVector (ThreadGroup threadGroup, String str) {

super(threadGroup, str);

this.str = str;

start();

}

public void addVector() {

Vector v = new Vector();

String refNo = "123";

String message = "Testing Message";

String api_Name = "OneApi";

String station_Name = "station process";

String status = "Norm";

String date_Time = "14/08/2001";

String token = "future";

v.addElement( refNo );

v.addElement( message );

v.addElement( api_Name );

v.addElement( station_Name );

v.addElement( status );

v.addElement( date_Time );

v.addElement( token );

buffer.addElement(v);

System.out.println("buffer size :"+buffer.size());

}

public void run () {

for (int i= 0;i < 1;i++ ) {

for(int j = 0; j < 20; j++) {

System.out.println("Thread Name :"+getName());

addVector ();

}

try{

sleep(3000);

}

catch (Exception e) {

System.out.println("Error :"+e);

}

}

}

}

class WriteFile extends Thread

{

String str ;

ThreadGroup threadGroup;

public WriteFile (ThreadGroup threadGroup, String str) {

super ( threadGroup, str );

this.str = str;

System.out.println("with in writefile const");

start();

}

public void run () {

try

{

if (threadGroup != null) {

Thread[] threads = new Thread ( threadGroup.activeCount() );

threadGroup.enumerate ( threads );

for ( int i = 0; i< threads.length; i++ )

if ( threads != null && threads != Thread.currentThread()) {

if (threads.isAlive()) {

if ( "addtovector".equalsIgnoreCase ( threads.getName()) ) {

System.out.println( threads.buffer.size() );

}

}

}

}

}

catch (Exception e)

{

System.out.println("with in catch :"+e);

}

}

}

public class LogManager

{

public static void main ( String args[] ) {

ThreadGroup threadGroup = new ThreadGroup("jeevan");

new AddVector(threadGroup,"addtovector");

new WriteFile(threadGroup,"writefile");

}

}

NOTICE TO USERS OF THIS SITE: By continuing to use this site, you certify that you have read and agree to abide by Sun's "Terms Of Use" which are linked to this site at the bottom of the page. Any users of this site who state that they work for Sun Microsystems, Inc. are deemed to be doing so solely for identification purposes. All information, data, text, software, music, sound, photographs, graphics, video, messages, or other materials ("Content") posted to this site by any users are the sole responsibility of those users. Sun does not guarantee the accuracy, integrity, or quality of such Content. Posting a name in a discussion forum places that personal information into a public forum. You are not signed in.

Products & APIs | Developer Connection | Docs & Training | Online Support

Community Discussion | Industry News | Solutions Marketplace | Case Studies

Glossary | Feedback | A-Z Index

For more information on Java technology

and other software from Sun Microsystems, call:

(800) 786-7638

Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.

Copyright 1995-2001 Sun Microsystems, Inc.

All Rights Reserved. Terms of Use. Privacy Policy.

[5498 byte] By [jeevankc] at [2007-9-26 4:08:38]
# 1
Hi, What about using PipedInputStream and PipedOutputStream? regards Stallon
stallon at 2007-6-29 13:11:00 > top of Java-index,Archived Forums,Java Programming...