【问题标题】:Is it wrong to use HashMap if I have 1M to 10M markers?如果我有 1M 到 10M 的标记,使用 HashMap 会不会出错?
【发布时间】:2016-10-14 08:41:40
【问题描述】:

我已经编写了这段代码来使用 infoWindows 填充我的地图,效果很好:

 query.addValueEventListener(new ValueEventListener()
                {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshots)
                    {
                        Marker marker;
                        for (DataSnapshot dataSnapshot : dataSnapshots.getChildren())
                        {
                          Location location = dataSnapshot.getValue(Location.class);
                          IdLocation.put(location,dataSnapshot.getKey());

                          marker = mgoogleMap.addMarker(new MarkerOptions()
                                   .position(new LatLng(location.getLatitude(), location.getLongitude()))                                        .title(getString(R.string.tipologia))
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_free)));

                         mapLocation.put(marker,location);

                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError)
                    {

                    }
                });

但我不知道它是否也适用于 1M / 10M 标记(我的应用程序需要大量可扩展)。在这种情况下,使用HashMap好还是我必须使用其他东西?问题也是 infoWindows 不接受任何参数...

谢谢

【问题讨论】:

  • 我认为在这种情况下使用 HashMap 是个好主意,但如果您希望从长远来看可扩展性,ConcurrentHashMap 会是一个更好的主意。

标签: java google-maps hashmap


【解决方案1】:

如果您需要这种可扩展性,我建议您使用 ConcurrentHashMap,您可以关注这篇文章以获得更深入的答案:

Scalability issue with HashMap in Multithreaded Multicore system

ConcurrentHashMap in Java?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    相关资源
    最近更新 更多