首页 > 编程知识 正文

在java中怎样创建一个线程,list线程安全的类

时间:2023-05-06 12:09:01 阅读:29578 作者:738

considera for-loopoverafunctionthattakesanarraylistreferenceandaddsanobjecttothatarraylist.iwouldnowliketoexecuteacharacharachachfuteachachfunctitition

is the ArrayList.add (methodthreadsafeifidon ' tcareaboutthesequencetheobjectsareaddedandnofunctionreadsormanipulatesanyarionyates

soionlywanttomakesurethatattheendoftheparallelcallallobjectsareaddedtothelist。

解决方案

No,it ' snot thread-safe.wrapyourlistusingcollections.synchronized list (,oruseexplicitsynchronizationwhenaccessingthrron

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。