Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestThreads {
- public static class Thread1 implements Runnable {
- @Override
- public void run() {
- try {
- Connection connection = DriverManager
- .getConnection("jdbc:mysql://localhost/test?"
- + "user=myuser&password=mypassword");
- Statement statment = connection.createStatement();
- statment.executeQuery("select * from `table1`");
- [...]
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static class Thread2 implements Runnable {
- @Override
- public void run() {
- try {
- Connection connection = DriverManager
- .getConnection("jdbc:mysql://localhost/test?"
- + "user=myuser&password=mypassword");
- Statement statment = connection.createStatement();
- statment.executeQuery("select * from `table2`");
- [...]
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void main(String[] args) {
- Thread thread1 = new Thread(new Thread1());
- Thread thread2 = new Thread(new Thread2());
- thread1.start();
- thread2.start();
- try {
- thread1.join(1000000);
- thread2.join(1000000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement