PrintWriter线程安全吗? [英] Is PrintWriter threadsafe?

查看:441
本文介绍了PrintWriter线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案



" Jeff Schwab" < JE ****** @ comcast.net>在消息中写道

新闻:rY ******************** @ comcast.com ...

"Jeff Schwab" <je******@comcast.net> wrote in message
news:rY********************@comcast.com...
是可以让多个线程同时使用同一个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.net>在消息中写道
新闻:rY ******************** @ comcast.com ...
"Jeff Schwab" <je******@comcast.net> wrote in message
news:rY********************@comcast.com...
是多个线程可以同时使用相同的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.net>在消息中写道

news:eu ******************** @ comcast.com ...
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.net> wrote in message
news:eu********************@comcast.com...
Silvio Bierman写道:
Silvio Bierman wrote:
" Jeff Schwab" < JE ****** @ comcast.net>在消息中写道
新闻:rY ******************** @ comcast.com ...
"Jeff Schwab" <je******@comcast.net> wrote in message
news:rY********************@comcast.com...
是多个线程可以同时使用相同的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 = -----
http://www.newsfeeds.com - 世界排名第一的新闻组服务!

----- ==超过100,000个新闻组--19个不同的服务器! = -----


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


这篇关于PrintWriter线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆