从单独的线程下载 XML/图像
我正在开发一个 Java ME 应用程序来从服务器下载内容。第一次应用程序从本地加载一些内容,并且第一个显示包含多个页面,我们可以使用右/左导航移动页面。当新页面出现时,下载将开始并更新当前屏幕中的新内容。当我慢慢地从第一页移动到第二页时,下载将开始并解析 xml
并在屏幕上显示内容。当我从 1 页面快速移动到 2 页面到 3 页面时,从 1 页面到 2 页面启动一个线程
进行下载,同时用户从 2 页面移动到 3 页面,我们将停止之前运行的线程
并为当前屏幕启动一个新线程。
问题是:
1. 如何停止 Java ME 中正在运行的线程?现在我在 run 方法中使用了一个 while 循环,并给布尔值 false,线程将在布尔值变为 true 时运行。有没有其他方法可以在运行时停止线程
?
I am developing a Java ME application to download content from server. First time application load some content from local and first display contains more than one pages and we can move pages using right/left navigation. When a new page comes download will start and update the new content in current screen. when I move slowly from first to second page download will start and parse the xml
and display content in screen. When I move fast from 1 to 2 to 3 page, from 1 to 2 start one thread
for download at same time user move from 2 to 3 we will stop previous running thread
and start a new thread for current screen.
Problems are:
1. How can I stop a running thread in Java ME? Now I have used one while loop in run method and give boolean value false, thread will run while boolean value becomes true
. Is there any other way to stop a thread
while running?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用布尔变量是最好的解决方案。您还可以使用 Thread 类中所有相关的常规方法,但使用这些方法会使您的应用程序不稳定。其中一些(例如挂起)会在某些设备上抛出一些奇怪且不可抛出的异常!
我有一个不相关的建议给你,如果可能的话,不要在 j2me 应用程序中使用 XML。由于移动处理器较弱,因此用 XML 替换常规文本,以便更快、更轻松地进行处理。
Using a boolean variable is the best solution here. you can also use all of related regular methods in Thread class, but using those make your application unstable. some of them (like suspend) throws some weird and unthrowable exceptions on SOME DEVICES!
I have an unrelated advice for you, don't use XMLs in j2me applications if at all possible. replace regular texts instead XMLs for faster and easier processing due to weak mobile processors.