PrintWriter线程安全吗?

编程入门 行业动态 更新时间:2024-10-23 08:31:07
本文介绍了PrintWriter线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

多个线程可以同时使用相同的PrintWriter吗?

Is it OK for multiple threads to use the same PrintWriter concurrently?

推荐答案

" Jeff Schwab" < JE ****** @ comcast>在消息中写道 新闻:rY ******************** @ comcast ... "Jeff Schwab" <je******@comcast> wrote in message news:rY********************@comcast... 是可以让多个线程同时使用同一个PrintWriter吗? Is it OK for multiple threads to use the same PrintWriter concurrently?

在这种情况下你会考虑线程安全行为吗? Silvio Bierman

What would you consider threadsafe behaviour in such a scenario? Silvio Bierman

Silvio Bierman写道: Silvio Bierman wrote: " Jeff Schwab" < JE ****** @ comcast>在消息中写道新闻:rY ******************** @ comcast ... "Jeff Schwab" <je******@comcast> wrote in message news:rY********************@comcast... 是多个线程可以同时使用相同的PrintWriter吗? Is it OK for multiple threads to use the same PrintWriter concurrently?

在这种情况下你会考虑线程安全行为吗?

What would you consider threadsafe behaviour in such a scenario?

好问题。我只是想确保I / O系统不会被混淆。如果两个线程的输出交织在一起就没关系。

Good question. I just want to make sure the I/O system won''t get confused. It''s OK if the output of the two threads is intertwined.

你是否介意单词或单词中的字符是否混合? 线程1试图打印线程1 ABCDEF 线程2试图打印线程2 GHIJKLM 以下是OK ? " TThhr 1 eadAe 2a GHd ABCIJKLMDEF" 我认为您应该同步实际的IO调用。我们所做的是利用一个 消息队列; 不同的线程丢弃队列中的消息对象,而低优先级的线程等待<队列中的,弹出消息,执行IO,然后等待下一个 消息。因此只有一个低优先级的线程实际上正在执行IO。 Jeff Schwab < JE ****** @ comcast>在消息中写道 news:eu ******************** @ comcast ... Do you mind if characters within words or words are mixed? Thread 1 trys to print "Thread 1 ABCDEF" Thread 2 trys to print "Thread 2 GHIJKLM" Is the following OK? "TThhr 1 eadAe 2a GHd ABCIJKLMDEF" I think you should synchronize the actual IO call. What we do is utilize a message queue; the different threads drop message objects in the queue while a low-priority thread waits on the queue, pops off a message, does the IO, then waits for the next message. So only one, low-priority, thread is actually doing the IO. "Jeff Schwab" <je******@comcast> wrote in message news:eu********************@comcast... Silvio Bierman写道: Silvio Bierman wrote: " Jeff Schwab" < JE ****** @ comcast>在消息中写道新闻:rY ******************** @ comcast ... "Jeff Schwab" <je******@comcast> wrote in message news:rY********************@comcast... 是多个线程可以同时使用相同的PrintWriter吗? Is it OK for multiple threads to use the same PrintWriter concurrently?

在这种情况下你会考虑线程安全行为?

What would you consider threadsafe behaviour in such a scenario?

好问题。我只是想确保I / O系统不会混淆。如果两个线程的输出交织在一起就没关系。

Good question. I just want to make sure the I/O system won''t get confused. It''s OK if the output of the two threads is intertwined.

~让我们linux~ ----- =通过新闻源发布。 Com,Uncensored Usenet News = ----- www.newsfeeds - 世界排名第一的新闻组服务! ----- ==超过100,000个新闻组--19个不同的服务器! = -----

~ Let us linux ~ -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- www.newsfeeds - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

更多推荐

PrintWriter线程安全吗?

本文发布于:2023-11-25 18:55:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   PrintWriter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!