Jackson Article 3 [concurrent programming of objectmapper]

Source: Internet
Author: User

First twoArticleAfter learning about the basic usage of Jackson, I still remember the first article, which is so troublesome for me to get an objectmapper object.
. We also use the singleton mode to obtain the result. Why is it not new? Let's look at a piece of data first.

I will convert testvo in our second article to jsoncommonutil. getmapperinstance (false). The average execution time of five times is 210 milliseconds, and the value of false is 9991.6 milliseconds after true.

I don't want to test its performance here (I will write an article dedicated to testing the performance of several JSON class libraries later that will be involved at that timeJSON-lib,Jackson, Gson ...... And other common class libraries
), And my machine is not powerful. I mainly want to explain that the performance difference between New objectmapper () and global use is roughly47Times. What is the concept of 47 times the world of money at this time? How many times does a system need to be converted!

You may have said that you are the only one in the world. Why waste time writing an article. Don't worry. Let me explain it to you! After all, it is global. So what will happen in the case of multithreading and concurrency? Will it disrupt our data? The data cannot be messy. If you have a million deposit bank system, you may cry at a very low pace!

Next, let's take a look at Jackson's official explanation of objectmaper: Jackson'sOrg. codehaus. Jackson. Map. objectmapper"Just works" for mapping JSON data into plain old Java objects ("pojos"). Source: http://wiki.fasterxml.co/JacksonInFiveMinutes

 

Java Code
    1. Objectmapper mapper =NewObjectmapper ();// Can reuse, share globally

Show off my poor English:
Objectmapper is only used to map JSON to pojo and can be reused globally.

Since we have said that we can only map JSON to pojo for global use, do we need to study it? I feel necessary! Because I do not know whether it is thread-safe. After all, data is the first. Next, let's test whether it is thread-safe in extreme cases.

 My test logic is as follows: when multiple thread threads 1mapper have been mapped to a certain object, let the thread sleep and then thread 2 execute. Check whether the Conversion Result of thread 2 is correct. Although it is a bit inaccurate, it can also be seen whether it is thread-safe. Because there are too many codes that are currently being sorted out, I will paste the code after finishing the sorting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.