JAVA代码如何优化?
黄舟
黄舟 2017-04-17 13:09:25
0
1
339
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
伊谢尔伦

First of all, the way the code is written is relatively clear. Except that querying Json data should be encapsulated into the DAO layer, it does not have extreme requirements on performance, and it is not recommended to do too much optimization.
But if it is really necessary, here are some optimization ideas:

  1. If your BlackList is large,
    1.1 You can estimate the number of retrieved values, and adjust the capacity and even the load factor when creating a new one to avoid opening up memory space multiple times;
    1.2 Or create it once and cache it directly, using a triggered update mechanism to avoid repeated creation;
    1.3 Replacing HashMap with TreeMap can slightly improve query performance. In fact, you can use Set in this scenario, which can slightly reduce memory overhead;
    1.4 You can write the ID of this List into redis or memcached, so that it does not occupy the memory space of this application.
  2. Json deserialization can use higher performance libraries, such as Jackson, fastjson
  3. If you can control the end where data is obtained, you can consider a higher-performance serialization method, such as protobuff.
  4. If the number of query result Lists can be estimated, the initial capacity can also be set.

It feels like you want 10,000 objects, but you don’t want to create 10,000 objects. This is a self-contradictory thing, and there seems to be no solution.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!