Results 1 to 5 of 5
Thread: Hash Table Synchronization....
- 04-20-2010, 06:15 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
Hash Table Synchronization....
hi ppl!!!
i have an issue regarding synchronization of hash table....
the structure of problem is as follows
class abc
{
public void method1()
{
//code for hash table generation....(hashtableobject.put)
}
public void method2()
{
//code for accessing hashtable....(hashtableobject.get)
}
}
class xyz
{
public static void main(String[] arg)
{
ServerSocket ss = new ServerSocket(XXXX);
Runnable runn = new pqr();
Thread thread = new Thread(runn);
thread.start();
while (true) {
Socket s = ss.accept();
efg st = new efg(s);
st.start();
}
}
class efg extends thread
{
DataInputStream dis;
DataOutputStream dos;
public efg(Socket s) throws Exception {
InputStream is = s.getInputStream();
dis = new DataInputStream(is);
OutputStream os = s.getOutputStream();
dos = new DataOutputStream(os);
}
public void run() {
pqr bt = new pqr();
try {
while (true) {
String message = dis.readUTF();
dos.writeUTF(bt.fh.method2(message));
}
} catch (Exception e) {
}
}
class global
{
abc obj = new abc();
}
class pqr extends global implements runnable
{
public void run()
{
obj.method1();
}
}
ok now the problem!!!!!
when thread.start() is running method1() runs in this thread where hash table is being generated i have debugged the code the data is being fed into the hash table!!!!
but when method2() is being run it show ht.size() is zero!!!
so any opne out the who can modify the code above so tat the hash table in both the threads can be synchronised!!!!!
i mean i can access hashtable in method2()!!!!!!
thnxxxx ppl!!!!
- 04-20-2010, 06:15 PM #2
- 04-21-2010, 05:55 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
problem soved.....
while i was debugging the above given code!!!
i found tat the the scope of the object of the class holding methods was not upto the extent till where it should be!!!
so the global class was not being used in the code!!!!
so to create the static object of the class i wrote a constructor!!!!
which worked out and the problem got solved!!!!!
yeppiiiiiiiiiiiiiiiiii!!!
- 04-21-2010, 09:04 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
I think your exclamation mark button is stuck.
- 04-21-2010, 09:39 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Hash Table Help
By michael_mke in forum New To JavaReplies: 3Last Post: 11-27-2008, 05:12 PM -
Hash table with double hashing
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:43 PM -
Hash table with linear probing
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:43 PM -
Hash table with separate chaining
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:42 PM -
Hash Table help
By rhm54 in forum New To JavaReplies: 0Last Post: 02-08-2008, 01:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks