Tag: multithreading

什么时候Java线程活着?

这是关于Java线程词汇的一个非常基本的问题。 我看不到任何可能的重复,但可能有。 在Oracles文档中, alive所指的是什么? 是在run()方法尚未完成时还是其他任何参数?

如何在Java Swing应用程序中添加简单的延迟?

我想知道如何在Java中的Swing应用程序中添加时间延迟,我使用了Thread.sleep(time) ,并且我也使用了SwingWorker但它不起作用。 这是我的代码的一部分: switch (state) { case ‘A’: if (charAux == ‘A’) { state = ‘B’; //Here’s where I’d like to add a time delay jLabel13.setForeground(Color.red); break; } else { //Here’s where I’d like to add a time delay jLabel12.setForeground(Color.red); break; } } 我希望你在使用SwingWorker时可以帮助我或解决我的疑虑。

使用Timer而不使用任何按钮从另一个JFrame调用

使用Timer在没有任何按钮的情况下从另一个调用一个JFrame:时间减少然后打开另一个没有任何按钮的JFrame。 请帮忙。 用于netbeans

线程和文件写入

我有一个使用20个线程的java程序。 他们每个人都将结果写在一个名为output.txt的文件中。 我总是在output.txt获得不同数量的行。 这可能是线程同步的问题吗? 有办法处理这个吗?

具有多客户端通信的Java Server。

我正在为一项作业制作游戏。 我有一个用Java设置的服务器和多客户端,我们正在使用MVC。 我需要有一个客户端将他们的名字发送到服务器然后当两个玩家在场时我需要将两个名字一起发送回客户端以及他们是哪个玩家编号(玩家一或玩家二)。 我不知道如何判断信息来自哪个线程或信息被发送到哪个线程,因此并非所有玩家都认为他们是玩家一。 谢谢。

多个弹跳球螺纹问题

我创建了一个程序,可以生成多个具有随机颜色,速度和半径的弹跳球。 当用户点击屏幕时,应出现一个新的随机球并在屏幕上移动。 但我有一个multithreading问题。 当我点击屏幕时,会出现一个球并且根本不会移动。 当另一次点击没有任何反应时。 BouncingBalls Class public class BouncingBalls extends JPanel implements MouseListener{ private Ball ball; protected List balls = new ArrayList(20); private Container container; private DrawCanvas canvas; private int canvasWidth; private int canvasHeight; public static final int UPDATE_RATE = 30; int x = random(480); int y = random(480); int speedX = random(30); int […]

Java EE规范和multithreading

我正在使用Struts和Spring编写Java EE应用程序。 在其中一个操作中,存在大量数据库处理,因此存在性能问题。 我想知道的是我可以在这里使用multithreading吗? 我认为Java EE规范不允许创建自定义线程,而不是由Server创建的线程(我使用Weblogic)。 请指导我完成这个。

什么是JVM调度算法?

我真的很好奇JVM如何与线程一起工作! 在我的互联网搜索中,我发现了一些关于RTSJ的资料,但我不知道这是否是我答案的正确方向。 我还在sun的论坛http://forums.sun.com/thread.jspa?forumID=513&threadID=472453中找到了这个主题,但这并不令人满意。 有人可以给我一些关于JVM调度算法的指示,材料,文章或建议吗? 我也在寻找有关调度程序中Java线程的默认配置的信息,例如“时间切片时每个线程需要多长时间”。 这个东西。 我将不胜感激任何帮助 ! 谢谢 !

Java中的“实现Runnable”与“扩展线程”

从我在Java中使用线程的时间开始,我发现了这两种编写线程的方法: 使用implements Runnable : public class MyRunnable implements Runnable { public void run() { //Code } } //Started with a “new Thread(new MyRunnable()).start()” call 或者,使用extends Thread : public class MyThread extends Thread { public MyThread() { super(“MyThread”); } public void run() { //Code } } //Started with a “new MyThread().start()” call 这两个代码块有什么显着差异吗?

如何正确使用Java Executor?

我在我的multithreading应用程序中使用过Java Executors,但我似乎无法弄清楚何时最好使用以下各种方法: 1。 ExecutorService executor=Executors.newFixedThreadPool(50); executor.execute(new A_Runner(… some parameter …)); executor.shutdown(); while (!executor.isTerminated()) { Thread.sleep(100); } 2。 int Page_Count=200; ExecutorService executor=Executors.newFixedThreadPool(50); doneSignal=new CountDownLatch(Page_Count); for (int i=0;i<Page_Count;i++) executor.execute(new A_Runner(doneSignal, … some parameter …)); doneSignal.await(); executor.shutdown(); while (!executor.isTerminated()) { Thread.sleep(100); } 3。 int Executor_Count=30; ThreadPoolExecutor executor=new ThreadPoolExecutor(Executor_Count,Executor_Count*2,1,TimeUnit.SECONDS,new LinkedBlockingQueue()); List<Future> futures=new ArrayList(3330); for (int i=0;i<50;i++) futures.add(executor.submit(new A_Runner(… some […]