Results 1 to 5 of 5
  1. #1
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Lightbulb 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!!!!

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

  3. #3
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default 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!!!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    I think your exclamation mark button is stuck.

  5. #5
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

Similar Threads

  1. Hash Table Help
    By michael_mke in forum New To Java
    Replies: 3
    Last Post: 11-27-2008, 05:12 PM
  2. Hash table with double hashing
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:43 PM
  3. Hash table with linear probing
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:43 PM
  4. Hash table with separate chaining
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:42 PM
  5. Hash Table help
    By rhm54 in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 01:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •