السلام عليكم ورحمة الله وبركاته
عندي مشكله بسيطه و الي اهيه هذا الكود مال PipedThread
المشكله اني اريد يوم اكتب واحد يطلعلي value حق key الاول
و اذا دخل key غير موجود value تكون null
و لازم key تكون random يعني اي رقم يدخله اليوزر
ممكن احد يساعدني فيه
محاولتي:
import java.io.*;
import java.util.*;
public class PipedThread extends Thread{
private DataInputStream dis;
private DataOutputStream dos;
private String name;
public static void main(String [] args){
try{
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
//pis.connect(pos);
PipedThread t1 = new PipedThread(pos,"t1");
PipedThread t2 = new PipedThread(pis,"t2");
HashMap map = new HashMap();
map.put("1" , "Alia");
map.put("2" , "Asma");
map.put("3" , "Laila");
map.put("4" , "Fatema");
map.put("5" , "Noura");
String name = (String)map.get("1");
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(map);
//System.out.println("the end");
}catch(Exception e){
System.err.println("ERROR : " + e);
}
}//main
public PipedThread(PipedInputStream p, String name){
super(name);
dis = new DataInputStream(p);
}
public PipedThread(PipedOutputStream p, String name){
super(name);
dos = new DataOutputStream(p);
}
public void run(){
if (Thread.currentThread().getName().equals("t1")){ // i am in thread 1
System.out.println();
}//if
}
}//class.jpg)