java - Java EE 应用程序中的并发

标签 java performance servlets jakarta-ee concurrency

之前我问过这个问题: Read quicktime movie from servlet in a webpage? 基本上,我使用 servlet 将电影文件流式传输到浏览器上的 Quicktime 插件(以便在根目录之外播放文件)。最后 Ryan Fernandes 问了我关于并发问题的问题。 我在这里还没有真正理解这个问题。

  • 使用 servlet 传输文件与传统方法的主要区别是什么?无论如何,服务器仍然必须将文件传输到客户端?如果不是,在后一种情况下服务器实际上如何将文件流式传输到插件?

  • Ryan 还询问了使用 servlet 的性能。因为它占用大量内存?当我们使用backing bean或者jsf、jsp(基于servlet)时,如果很多用户同时访问,创建的实例数量是巨大的。它还需要大量的内存,我们该如何解决呢?

请帮我解决这些问题。如果您有任何关于这些问题的好文章:并发、多线程、性能可以与我分享,我是一个新手。 非常感谢。 问候 K.

最佳答案

好吧,如果你指的是这个评论:

how many users are you expecting this servlet to concurrently service? Are you sure the I/O you've got going with creating the Fileinputstream is going to work for more than a few concurrent requests?

那么他的意思是,如果您尝试手动使用 100 个单独的线程打开同一个文件,可能会出现问题。

网络服务器如何处理这种情况不应该真正困扰您,因为他们可以以任何他们想要的方式实现它。

关于主要问题,这是我在 javadoc 中找到的内容:

class FileInputStream
public FileChannel getChannel()

Returns the unique FileChannel object associated with this file input stream.

class FileChannel

File channels are safe for use by multiple concurrent threads. The close method may be invoked at any time, as specified by the Channel interface. Only one operation that involves the channel's position or can change its file's size may be in progress at any given time; attempts to initiate a second such operation while the first is still in progress will block until the first operation completes. Other operations, in particular those that take an explicit position, may proceed concurrently; whether they in fact do so is dependent upon the underlying implementation and is therefore unspecified.

关于java - Java EE 应用程序中的并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3155388/

相关文章:

java - 如何处理参数值中的特殊字符?

java - 未在 servlet 的请求中插入自定义 header

java - 如何在 dr Java 程序中创建计数器

java - 有没有完全免费并且可以用于商业用途的 OpenJDK

c# - 为什么 List<T>.Sort 使用 Comparer<int>.Default 比等效的自定义比较器快两倍以上?

Java多线程问题

performance - Flutter - CustomPaint 更高效的平移和缩放

java - apache wicket 世界中的母版页

java - 更改 json 中的数字

servlets - 确切地说,@Inject 注释何时在 Servlet 中启动 SessionScoped bean 的注入(inject)?