Java多线程一次运行多个方法的最简单方法? [英] Java multithreading easiest way to run multiple methods at once?

查看:144
本文介绍了Java多线程一次运行多个方法的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从未使用过多线程,我了解它在基本级别上是什么.我想知道一次执行三个方法的最简单,最有效的方法是什么?

I've never had to multithread before, I understand what it is at a basic level. I'm wondering what would be the simplest and most efficent way to execute three methods at once?

例如

public void test(){
method1();
method2();
method3();
}

基本上我想同时执行1,2和3.我正在寻找对执行此操作有用的任何示例或资源.

Basically I want to execute 1,2 and 3 at the same time. I'm looking for any examples or resources which would be useful for doing this.

谢谢!

推荐答案

如果您的三个方法不共享状态,则可以为每个方法增加一个线程.

If your three methods do not share state, you can just spin up a thread for each method.

http://java.sun.com/docs /books/tutorial/essential/concurrency/runthread.html

这篇关于Java多线程一次运行多个方法的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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