DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: static HashMap is created many times

  1. #1
    Join Date
    Mar 2005
    Location
    Istanbul
    Posts
    10

    static HashMap is created many times

    we are developing robots with friends for robocode, a game in which robots fights that you write in java, probably you know it.

    we want to keep information of robots in a HashMap. when our robots detect an enemy robot they will add that enemy as an object to the hashmap.
    each of the robots are a thread =>that means multiple threads will add objects to the same hashmap. so hashmap will be static and the method will be synchronized. we did like this. our problem is about the static part. there have to be one hashmap and every thread(robot) must use it but each thread(robot) use a different hashmap.

    how will we be able to use one unique hashmap for all threads.

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    private static Map myMap = java.util.Collections.synchronizedMap(new HashMap());

  3. #3
    Join Date
    Mar 2006
    Posts
    7
    You should create an extended hashmap,see here

    http://www.developerzone.biz/index.p...d=90&Itemid=36
    www.hotdir.biz Hot Java Directory

Similar Threads

  1. KeyListener not responding
    By lordanki in forum Java
    Replies: 3
    Last Post: 04-04-2006, 10:13 AM
  2. Adding Salesmen question
    By homer2001 in forum Java
    Replies: 0
    Last Post: 03-12-2006, 09:30 PM
  3. Trouble buffering transparent gif
    By axlan in forum Java
    Replies: 2
    Last Post: 06-22-2005, 08:21 AM
  4. Top fixed screen
    By Cheng in forum Web
    Replies: 1
    Last Post: 11-06-2001, 10:43 AM
  5. Replies: 13
    Last Post: 10-03-2001, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center