根据java.io/java.nio进行阻塞 [英] Blocking in terms of java.io/java.nio

查看:72
本文介绍了根据java.io/java.nio进行阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看过...

使用流的类位于两个包中: java.io和java.nio.前者的课程 输入/输出(I/O)的阻塞:当一个字节正在读取/写入字节时 进程,它们变得无法用于其他执行线程.这 后者提供了具有改进性能的非阻塞I/O.

Classes that work with streams are located in two packages: java.io and java.nio. Classes from the former implement blocking of input/output (I/O): When bytes are being read/written by a process, they become unavailable for other threads of execution. The latter package offers non-blocking I/O with improved performance.

...,并希望对此有所了解.阻塞是否只会影响单个相关线程,而不会阻塞源(即文件或数据库)本身,准备供其他流访问?还是阻塞实际上阻止了源本身的访问,直到当前线程完成读取操作为止?

... and would like to understand this a bit more. Does blocking only impact the single relevant thread, but leave the source (i.e. file or database) itself unblocked, ready to be accessed by other streams? Or does the blocking actually prevent the source from being accessed itself, until the current thread is done with the reading?

推荐答案

阻塞基本上是指当线程调用read()或write()时,它被阻止执行任何其他操作,直到有一些数据要读取或数据被写入.同时,线程可以执行其他操作.

Blocking basically refers to when a thread invokes a read() or write(), it is blocked from doing anything else until there is some data to read or the data is written. The thread can do NOTHING else in the meantime.

所以阻塞与线程本身有关,而不与数据源有关.

So blocking is to do with the thread itself, not the data source.

这篇关于根据java.io/java.nio进行阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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