Java applet 在 Web 上的可用性

发布于 2024-09-11 10:01:13 字数 2794 浏览 4 评论 0原文

对于我们大学的电子学习项目,我们使用 Java 小程序在 Ilias 学习单元内显示一些交互式内容(例如一些交互式函数绘图或一些简单的问答系统或其他交互式元素以及这些元素的任意组合)。

我们决定使用 Java,因为我们想要一个开放的解决方案(当时 HTML5 还没有真正可用,Flash 曾经是、现在也不是真正的选择)。

几年后的现在,我确实感觉到 Java 并不能真正用于 Web。主要是因为有很多问题,我无法真正解决所有情况。

所以,我的问题是:Java 是否不适合网络,或者我做错了什么?你能指出我如何解决这些问题吗?

我当时遇到的问题:

  • Java 小程序需要很长时间才能加载。即使是一个非常简单的小小程序,有时也需要一分钟左右的时间来加载。这是为什么? Java框架真的比Qt或其他框架大很多吗?还是VM这么大?还是虚拟机太慢了?

  • 浏览器(或者至少是 Chrome 中的选项卡)变得非常慢,尤其是在加载小程序时以及之后。

  • Java 小程序在每个系统上看起来都不同。 UI 控件完全不同,而且行为也略有不同。有时它是原生的外观(或类似的外观),有时它完全是自己的东西。此外,字体大多不同,并且通常支持不同的 Unicode 字符子集。这对我们来说是一个真正的问题,因为我们大量使用 Unicode 来表示数学符号,并且我们收到很多报告称某些符号对某些人不起作用。此外,由于每个系统上的字体大小不同,我收到报告称文本是为少数人剪裁的(或在 JLabel 中用“...”缩短)。我现在通过在 JAR 中包含 TTF 解决了这个问题。这大部分都有效。即使使用独特的字体,有时我仍然会收到这些“...”报告。

  • 有时内存使用量非常高(但并非总是如此)。

  • 加载包含多个小程序的页面时,浏览器崩溃和/或多个小程序无法正确加载的可能性非常高。而且整个操作系统变得非常慢。

  • 有时,Java 小程序不会在浏览器 X 中加载,而是在浏览器 Y 中加载。单击几次重新加载或重新启动浏览器/系统后,该行为可能会发生切换。例如,似乎小程序在 Firefox 中加载的可能性较高(也并非总是如此,但大多数情况下,至少在重新加载时单击一两次后),而在 Chrome 上加载的可能性较小(但如果我幸运的话,有时它也可以工作) 。根据系统的不同,可能有不同的浏览器效果最好。尽管从来没有一个浏览器可以完美运行。此行为出现在我们测试过的所有系统上(不同的 Linux 发行版,32 位和 64 位、Windows XP/Vista/7、Mac OS X)。

  • 有时,当我切换到另一个选项卡并返回时,小程序会保持空白。有时至少需要很长时间才能再次出现。

  • 它耗尽了所有的CPU。即使我关闭了小程序的所有选项卡。我必须退出浏览器才能解决此问题。

我们遇到这些问题的一些示例:

如果您查看这些示例,什么是 Java 的良好替代解决方案?我考虑过使用最新浏览器的 HTML + JavaScript(如果我们告诉用户他们应该使用 WebKit 基于浏览器等),尽管我认为其中一些示例可能很难实现(或者至少比 Java 更难)。

For our eLearning project in our university, we are using Java applets to show some interactive stuff (like some interactive function plotting or some simple question/answer system or other interactive elements and any combination on those) inside of Ilias learning units.

We decided for Java because we wanted an open solution (and HTML5 was not really available at that time and Flash was and is not really an option).

Now, a few years later, I really got the feeling that Java is not really usable for the web. Mostly because of a lot of problems I haven't really been able to fix for all cases.

So, my question: Is Java just not the right thing for the web or am I doing something wrong? Can you point out how I could solve these problems?

Problems I have encountered in the time:

  • A Java applet take ages to load. Even if it is a very simple small applet, it sometimes takes about a minute to load. Why is that? Is it really that the Java framework is so much bigger than Qt or other frameworks? Or is the VM so big? Or is the VM so slow?

  • The browser (or at least the tab in Chrome) gets very slow esp while loading the applet but also afterwards.

  • The Java applet looks different on every system. The UI controls are totally different and also behave slightly different. Sometimes it's the native look (or kind of it), sometimes it's completely something own. Also the font is mostly different and often supports a different subset of Unicode characters. This is a real problem for us because we use Unicode a lot for math symbols and we got a lot of reports that some symbols don't work for some people. Also as the font has different size on each system, I got reports that the text is cut out for a few people (or shortened by "..." in a JLabel). I have gotten around this problem now by including a TTF in the JAR. That works mostly. Still sometimes I get these "..." reports even with the unique font.

  • Sometimes the memory usage is incredibly high (but not always).

  • When loading a page with multiple applets, the chances become very high that the browser crashes and or multiple applets don't load correctly. Also the whole operating system gets very slow.

  • Sometimes, the Java applet doesn't load in browser X but in browser Y. After clicking a few times on reload or restarting the browser/system, that behavior may switch. For example, it seems that chances are higher that the applet load in Firefox (also not always, but mostly, at least after clicking one or two times on reload) and less likely on Chrome (but if I am lucky it also works sometimes). Depending on the system, it may be different browsers which work best. Though there is never a browser which works perfect. This behavior is on all the systems we have tested (different Linux distributions, both 32bit and 64bit, Windows XP/Vista/7, Mac OS X).

  • Sometimes, the applet stays blank when I switched to another tab and return back. Sometimes it at least takes a very long time until it shows up again.

  • It eats up all the CPU. Even after I have closed all tabs with the applets. I have to quit the browser to resolve this.

Some examples where we have these problems:

If you look at these examples, what would be a good alternative solution to Java? I thought about HTML + JavaScript with recent browsers (it is not really a problem if we tell our users that they should use WebKit based browsers or so), although I think that some of these examples might be very hard to implement (or at least harder than in Java).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

誰認得朕 2024-09-18 10:01:13

尝试WebStart。基本上,它允许您从 Web 链接启动独立的 Java 应用程序。您的所有资源都缓存在客户端,因此后续启动速度要快得多。

从您发送的链接来看,Geonext 似乎存在问题。当同一页面上有多个实例时,它似乎效果不佳。

您是否尝试过在独立的 Java 应用程序中运行 Geonext 屏幕?这也可能是您的输入数据的问题。

就外观而言,如果您希望它独立于操作系统,则可以明确设置它。

Geonext 很可能使用一些静态变量。当页面包含多个打开的实例时,这可能会产生竞争条件。您可能想检查文档...

Try WebStart. Basically, it allows you to start a standalone Java application from a web link. All your resources are cached client-side, so subsequents starts are much faster.

From the link you've sent, there seems to be a problem with Geonext. It does not seem to work well when there are several instances on the same page.

Have you tried to run the Geonext screens in a standalone Java application? It could also be a issue with your input data.

As far as the look and feel is concerned, you can set it explicitly if you want it to be OS independent.

It's quite possible that Geonext uses some static variables. This could create race conditions when a page contains several instances opened. You might want to check the documentation...

梦巷 2024-09-18 10:01:13

Java 小程序需要很长时间才能加载。甚至
如果是一个很简单的小小程序,
有时需要大约一分钟的时间
加载。这是为什么?真的是这样吗
Java 框架要大得多
比 Qt 或其他框架?或者是
虚拟机这么大?还是虚拟机太慢了?

这完全取决于它运行的机器、Web 浏览器和 Java 版本。我加载了您链接到的第一个示例页面,虽然加载确实需要一些时间,但它还在双核计算机上同时加载 19 个小程序。

话虽如此,一页上有 19 个小程序是很荒谬的。

浏览器(或者至少是选项卡)
Chrome)变得非常慢,尤其是
还加载小程序
之后。

加载包含多个内容的页面时
小程序,机会变得非常高
浏览器崩溃和/或
多个小程序无法正确加载。
整个操作系统也得到
非常慢。

我没有注意到小程序加载方式的问题,除非您一次加载很多小程序。

同样,这不仅依赖于 Java,还依赖于加载它的浏览器。

它耗尽了所有的CPU。即使我关闭了小程序的所有选项卡。我必须退出浏览器才能解决此问题。

当您离开页面时,小程序并不总是被卸载。当您离开页面时,小程序的 stop() 方法始终会运行,但 destroy() 方法和小程序的实际卸载可能不会。

在 Firefox 3.6 中,卸载小程序之前似乎要等待 1-2 分钟。

Java 小程序看起来不同
每个系统。 UI 控件是
完全不同,而且行为也不同
略有不同。有时它是
原生外观(或类似的外观),有时
它完全是自己的东西。还
字体大多不同,而且经常
支持 Unicode 的不同子集
人物。这是一个真正的问题
我们因为我们经常使用 Unicode
数学符号,我们有很多
报告某些符号不起作用
对于某些人来说。也因为字体有
每个系统上的大小不同,我得到
报道称该文本被剪裁为
很少有人(或在 a 中缩写为“...”)
J标签)。我已经解决了这个问题
现在的问题是在
罐。这大部分都有效。仍然
有时我会收到这些“...”报告
即使使用独特的字体。

Java 有两个小程序基类。第一个是旧式 java.applet.Applet 类。另一个是较新的 javax.swing.JApplet 类。

前者使用 AWT 进行渲染,它构建在系统的本机小部件上。后者使用 Swing 进行渲染,并且应默认为跨平台 Metal (海洋)主题。

Swing 教程有一个关于如何制作 Applet 的页面。

A Java applet take ages to load. Even
if it is a very simple small applet,
it sometimes takes about a minute to
load. Why is that? Is it really that
the Java framework is so much bigger
than Qt or other frameworks? Or is the
VM so big? Or is the VM so slow?

That depends entirely on the machine it's running on, the web browser, and the Java version. I loaded the first example page you linked to, and while it did take a moment to load, it was also loading 19 applets simultaneously on a dual-core machine.

Having said that, 19 applets on one page is ridiculous.

The browser (or at least the tab in
Chrome) gets very slow esp while
loading the applet but also
afterwards.

When loading a page with multiple
applets, the chances become very high
that the browser craches and or
multiple applets don't load correctly.
Also the whole operating system gets
very slow.

I haven't noticed problems with the way applets load other than when you're loading a lot of them at once.

Again, this isn't just dependent on Java, but also the browser that loads it.

It eats up all the CPU. Even after I have closed all tabs with the applets. I have to quit the browser to resolve this.

Applets are not always unloaded when you leave a page. The applet's stop() method is always run when you leave a page, but the destroy() method and the actual unloading of the applet may not.

In Firefox 3.6, it appears to wait for 1-2 minutes before unloading an applet.

The Java applet looks different on
every system. The UI controls are
totally different and also behave
slightly different. Sometimes it's the
native look (or kind of it), sometimes
it's completely something own. Also
the font is mostly different and often
supports a different subset of Unicode
characters. This is a real problem for
us because we use Unicode a lot for
math symbols and we got a lot of
reports that some symbols don't work
for some people. Also as the font has
different size on each system, I got
reports that the text is cut out for a
few people (or shortened by "..." in a
JLabel). I have gotten around this
problem now by including a TTF in the
JAR. That works mostly. Still
sometimes I get these "..." reports
even with the unique font.

Java has two base applet classes. The first is the old-style java.applet.Applet class. The other is the newer javax.swing.JApplet class.

The former uses AWT for rendering, which builds on the system's native widgets. The latter uses Swing for rendering and should default to the cross-platform Metal (Ocean) theme.

The Swing tutorial has a page on How to Make Applets.

你如我软肋 2024-09-18 10:01:13

Java applet 在本世纪初就已经很现代了。目前只有少数站点使用 Java applet,这可能是浏览器支持不是最佳的原因之一。

从我在浏览器卡住之前所看到的情况来看,您的小程序似乎只是在绘制各种图表。

我建议尝试一种专注于绘制图表的现代 JavaScript 库:
http://javascript.open -libraries.com/utilities/chart/20-best-javascript-charting-and-plotting-libraries/

或者,如果您需要的选项比库提供的更多,并且您不太关心跨浏览器兼容性,您可以使用HTML5 元素和 SVG - 除 Internet Explorer 之外的所有浏览器都对这些元素有很好的支持。

如果您不需要图表是交互式的,您可以使用 PHP、Ruby、Python、Java 或其他方式在服务器上呈现它们,并将它们作为纯图像发送到浏览器。

如果您需要表达数学表达式,请考虑 MathML 或可能由服务器脚本。

Java applets were modern at the beginning of this century. There are only a few sites using Java applets today and this may be one of the reasons why the browser support is not optimal.

From what I've seen before my browser got stuck, your applets seem to be just drawing various charts.

I would suggest trying one of the modern JavaScript libraries which focus on drawing charts:
http://javascript.open-libraries.com/utilities/chart/20-best-javascript-charting-and-plotting-libraries/

Alternatively, if you need more options than the libraries offer and you do not care much about cross-browser compatibility, you may use the <canvas> HTML5 element and SVG - all browsers except for Internet Explorer have decent support of these.

If you do not require the charts being interactive, you can render them on the server using PHP, Ruby, Python, Java, or whatever and send them as plain images to the browser.

If you need to express mathematical expressions, consider MathML or plain images possibly rendered on the fly by a server script.

雨后咖啡店 2024-09-18 10:01:13

1.“Java 小程序需要很长时间才能加载。”

并不真地。当您加载第一个小程序时,您还加载了 JVM,与 JavaScript 引擎不同,JVM 在您启动浏览器时不会加载。 JVM启动时间并不比JavaScript启动时间长,但最后一个隐藏在浏览器启动时间中......
有一个名为 Jigsaw 的项目,它将当前的 JVM 拆分为模块,并使初始启动速度更快,并计划在 Java 9.2 上运行。

“浏览器(或至少 Chrome 中的选项卡)变得非常慢,尤其是在加载小程序,但之后也是如此。”

加载 JVM 时,速度自然会变慢。但是,如果浏览器随后变慢,则您的小程序中可能存在一些使用过多 CPU 时间的错误。这与 JavaScript 没有什么不同,JavaScript 也会使浏览器变得非常慢。您可能需要分析您的小程序,以便找出您的资源的去向。我确实在使用 Chrome 时遇到了问题,但众所周知,它对小程序的支持很糟糕......

3.“Java 小程序在每个系统上看起来都不同。”

如果您将 Swing 与非本机 外观和感觉 事实并非如此。我个人更喜欢现代 Nimbus 的外观和感觉。

如何在 main 中设置 Nimbus 外观

4.“有时内存使用量非常高(但并非总是如此)。”

分析您的代码,您可能正在执行过多的内存分配。阅读对象池和其他减少内存碎片的方法。这通常是 Applet 编码错误的迹象,而不是 Applet 技术存在问题。

5.“当加载包含多个小程序的页面时,浏览器崩溃和/或多个小程序无法正确加载的可能性非常高。而且整个操作系统也会变得非常慢。”

就我个人而言,我不会在一个页面上有多个小程序。看看是否可以合并它们。有些浏览器对此的支持非常差。但更重要的是,即使技术没有搞砸,它也不是很用户友好。

6.“有时,Java 小程序不会在浏览器 X 中加载,而是在浏览器 Y 中加载”

这是现代浏览器的一个已知问题,往往不能很好地支持插件。这实际上与第 5 个问题相同。当您在页面上仅使用单个小程序时,此问题更为罕见。

7.“有时,当我切换到另一个选项卡并返回时,小程序会保持空白。有时至少需要很长时间才能再次显示。”

与 5 和 6 相同的问题。插件代码 (NPAPI) 尚未现代化以正确支持插件。浏览器没有告诉插件它必须正确地重绘其内容。或者它可能已经崩溃了。如果您只使用单个小程序,此问题也更罕见。

8.“它耗尽了所有的CPU。即使我关闭了小程序的所有选项卡。我必须退出浏览器才能解决这个问题。”

当您关闭选项卡时,小程序不会关闭。当小程序退出时它们会关闭,您需要在代码中执行此操作。您的代码必须侦听某些事件、清理并退出。我不记得这个代码,因为我通常复制粘贴它。也有可能 AWT/Swing 如果你在窗口资源消失时不关闭它,它就会崩溃......

在某些方面你是对的,在其他方面你是对的您遇到问题是因为您使用的是过时的库(例如具有默认外观的 AWT 或 Swing)或者不了解如何管理小程序生命周期。

1. "A Java applet take ages to load."

Not really. Whey you load your first applet, you also load the JVM which, unlike the JavaScript engine, is not loaded when you start your browser. The JVM startup time are not longer than the JavaScript startup time, but the last one are hidden in the browser startup time...
There are a project called Jigsaw which will split the current JVM into modules and make this initial startup much faster, and are scheduled for Java 9.

2. "The browser (or at least the tab in Chrome) gets very slow esp while loading the applet but also afterwards."

While loading the JVM, it's natural that things slow down. However, if the browser is slow afterwards, you probably have some bug in your applet that use excessive CPU time. This isn't any different from JavaScript which also can make the browser very slow. You may need to profile your applet in order to figure out where your resources go. I do have problems with Chrome, but its support for applets are known to be crappy...

3. "The Java applet looks different on every system."

If you use Swing with a non-native look and feel it does not. Personally I prefer the modern Nimbus look and feel.

How to set Nimbus look and feel in main

4. "Sometimes the memory usage is incredibly high (but not always)."

Profile your code, you are probably doing excessive memory allocations. Read up on object pools and other methods to decrease memory fragmentation. This are usually the sign of a badly coded Applet, rather than a problem with the Applet technology.

5. "When loading a page with multiple applets, the chances become very high that the browser crashes and or multiple applets don't load correctly. Also the whole operating system gets very slow."

Personally I would not have multiple applets on a page. See if you can merge them. Some browsers have very bad support for this. But more importantly it's not very user-friendly even when the technology do not mess it up.

6. "Sometimes, the Java applet doesn't load in browser X but in browser Y"

This is a known problem with modern browsers that tend to not support plugins well. This are actually the same problem as number 5. This problem are much more rare when you only use a single applet on your page.

7. "Sometimes, the applet stays blank when I switched to another tab and return back. Sometimes it at least takes a very long time until it shows up again."

Same problem as 5 and 6. The plugin code (NPAPI) haven't been modernized to properly support plugins. The browser is not telling the plugin that it must redraw it contents properly. Alternatively it may have crashed. This problem are also more rare if you only use a single applet.

8. "It eats up all the CPU. Even after I have closed all tabs with the applets. I have to quit the browser to resolve this."

Applets do not close when you close the tabs. They close when the applet exits, which you need to do in your code. Your code has to listen to some event, clean up, and exit. I don't remember the code for this as I usually copy-paste it. Also it's possible that AWT/Swing freaks out if you don't shut it down when its window resource dies...

On some of this you are right, and on others you have problems because you are using outdated libraries (like AWT or Swing with default look and feel) or do not understand how to manage the applet life-cycle.

忆伤 2024-09-18 10:01:13

如果您了解 Java 并且熟悉 applet 代码,请查看 GWT (Google Web Toolkit)。它允许您编写 Java 代码并将其转换为 JavaScript。

If you know Java and are comfortable in applet code, look at GWT (Google Web Toolkit). It allows you to write Java code and it translates it to JavaScript.

Hello爱情风 2024-09-18 10:01:13

如果移动访问很重要,那么 HTML + JavaScript 选项确实是您拥有的唯一合适的选项,因为它是所有 Apple 设备、Android 设备以及许多其他支持 WebKit。 (我们以这种方式实现了德克萨斯州主页上的所有互动。http://www.txstate.edu/)

如果您同意仅在桌面上交付,Flash 就变得非常可行,< a href="https://en.wikipedia.org/wiki/Thoughts_on_Flash" rel="nofollow noreferrer">史蒂夫·乔布斯的抗议相反。 :) 我们的一些学习模块是基于该技术构建的。

If mobile access is important, the HTML + JavaScript option is really the only decent one you have, as it's the most widely-supported implementation technology across all of the Apple devices, Android devices, and many of the other mobile devices that support WebKit. (We implemented all of the interactivity on the Texas State homepage this way. http://www.txstate.edu/)

If you're OK with desktop-only delivery, Flash becomes pretty viable, Steve Jobs' protestations to the contrary aside. :) Some of our learning modules are built on that technology.

小草泠泠 2024-09-18 10:01:13

从描述来看,大多数这些问题都是代码编写方式的问题。不幸的是,在我们的行业中,高质量的产品很少见。

如果小程序需要一分钟才能加载,则可能是 DNS 问题或其他一些与 I/O 相关的问题。 (它取决于网络、文件还是 CPU?)

在现代计算机上,内存使用情况很难有效测量。在具有 GB 内存的现代计算机上,JRE 的开销应该非常小。

如果使用Swing,那么PL&F可以设置为交叉平台(Metal、Nimbus 或下载的实现)。

字体也可以动态下载。

Most of these problems would appear from the description to be problems with the way the code is written. Unfortunately in our industry, quality is rare.

If an applet takes a minute to load that could be a DNS problem, or some other I/O related issue. (Is it dependent upon network, file or CPU?)

On modern computers memory usage is surprisingly difficult to measure effectively. The overhead of the JRE on a modern computer with gigabytes of memory should be pretty small.

If you use Swing, then the PL&F can be set to be cross platform (Metal, Nimbus or a downloaded implementation).

Fonts can also be dynamically downloaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文