Using BufferedReader and InputStreamReader with virtual threads
Alan Bateman
Alan.Bateman at oracle.com
Mon Aug 10 19:02:40 UTC 2020
On 10/08/2020 17:07, Karsten Pagel wrote:
> Well, since i'm just experimenting, it would be exaggerated to say,
> that i'm running into issue ;-)
>
> i stumbled over it, when creating a simple testcase to check out, how
> to use virtual threads and to do some first steps...
> i have a fixed-size executorservice with one single worker-thread used
> as carrier-executer and started two virtual-threads - each opening a
> tcp-connection to a simple chatserver. i used the buffered reader for
> simplicity (each virtual thread should print complete textlines send
> to them, thats why is used BufferedReader.readLine()).
> Since it didn't do what i expected to do (only one of them printing
> out messages), i started to dig deeper... it works fine when using the
> inputstream directly.
> i think, there may be many third-party-libs using bufferedreader (for
> example reading csv-files row by row) or inputstreamreaders for
> charset-conversation - thats why i'm asking.
>
> I took a look at the (Buffered)Reader-class and your right. Since the
> lock-object is visible to subclasses it's impossible to replace it
> with a ReentrentLock without breaking compatibility with other classes...
Yes, but they are supposed to use a j.u.concurrent lock when not
extended. It's an oversight, or rather we changed some of the classes
but not all of them. We'll sort it out. Thanks for pointing it out.
-Alan
More information about the loom-dev
mailing list