Home  >  Q&A  >  body text

java - spring MVC框架Controller层中应该使用StringBuffer还是StringBuilder?

spring MVC框架Controller层中应该使用StringBuffer还是StringBuilder?

大家讲道理大家讲道理2744 days ago939

reply all(4)I'll reply

  • 阿神

    阿神2017-04-18 10:50:37

    If you use it as a global variable, you can only use StringBuffer, because spring mvc is not thread-safe. If it is only used as a local variable, use stringBuilder. The functions of the two of them are exactly the same, but the methods of StringBuffer are all synchronized methods, which improves performance under multi-threading. Worse than StringBuilder.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:50:37

    StringBuffer thread safe
    StringBuilder thread unsafe

    reply
    0
  • 阿神

    阿神2017-04-18 10:50:37

    Except for the thread problem, I think everything else is the same

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:50:37

    There is no thread safety issue when written in a method. . . Stringbuilder speed comparison, it is recommended to use it when operating large amounts of data

    reply
    0
  • Cancelreply