Win32 only: Thread.join() does not work if there are multiple threads. Thread.join(Int)
works if the argument is greater than 0.
Steps to reproduce
Compile the attached code
Run java ThreadJoinTest <some file> 2 0
// compare with ThreadJoinTest <some file> 2 1
/**
* A class to test file io - io to same and different files.
* @author Pavani Diwanji
*/
class bulkwriter extends Thread
{
String fname;
int io_size;
bulkwriter (String fn, int ios)
{
super("bulkwriter " + fn);
fname = fn;
io_size = ios;
}
public void run()
{
// stub
System.out.println(getName() + ".run() ends");
}
} // end class bulkwriter
class ThreadJoinTest
{
public void diff_io(String fname,
int num_threads,
int io_size,
int join_wait)
{
// local variables
int i;
bulkwriter w[] = new bulkwriter[num_threads];
// message
System.out.println("Starting diff io test..");
for (i = 0; i<num_threads; ++i)
{
w[i] = new bulkwriter(fname+i, io_size);
w[i].start();
}
for (i = 0; i < num_threads; ++i)
{
try
{
System.out.println("Join: " + w[i].getName());
if (join_wait < 1)
w[i].join();
else
w[i].join(join_wait);
}
catch (InterruptedException e)
{
System.out.println(e.getMessage());
}
} // end for(num threads)
// message
System.out.println("bulk writing done");
}
public static void print_format()
{
System.out.println("format: java io <filename> <#threads> <wait time>");
}
public static void main(String argv[])
{
int num_threads=0;
int join_wait = -1;
if ( argv.length != 3 )
{
print_format();
return;
}
try
{
num_threads = Integer.parseInt(argv[1]);
join_wait = Integer.parseInt(argv[2]);
}
catch(Exception e)
{
e.printStackTrace();
print_format();
}
// convert to milliseconds
join_wait *= 1000;
// run test
new ThreadJoinTest().diff_io(argv[0], num_threads, 0, join_wait);
} // end main()
} // end class io
works if the argument is greater than 0.
Steps to reproduce
Compile the attached code
Run java ThreadJoinTest <some file> 2 0
// compare with ThreadJoinTest <some file> 2 1
/**
* A class to test file io - io to same and different files.
* @author Pavani Diwanji
*/
class bulkwriter extends Thread
{
String fname;
int io_size;
bulkwriter (String fn, int ios)
{
super("bulkwriter " + fn);
fname = fn;
io_size = ios;
}
public void run()
{
// stub
System.out.println(getName() + ".run() ends");
}
} // end class bulkwriter
class ThreadJoinTest
{
public void diff_io(String fname,
int num_threads,
int io_size,
int join_wait)
{
// local variables
int i;
bulkwriter w[] = new bulkwriter[num_threads];
// message
System.out.println("Starting diff io test..");
for (i = 0; i<num_threads; ++i)
{
w[i] = new bulkwriter(fname+i, io_size);
w[i].start();
}
for (i = 0; i < num_threads; ++i)
{
try
{
System.out.println("Join: " + w[i].getName());
if (join_wait < 1)
w[i].join();
else
w[i].join(join_wait);
}
catch (InterruptedException e)
{
System.out.println(e.getMessage());
}
} // end for(num threads)
// message
System.out.println("bulk writing done");
}
public static void print_format()
{
System.out.println("format: java io <filename> <#threads> <wait time>");
}
public static void main(String argv[])
{
int num_threads=0;
int join_wait = -1;
if ( argv.length != 3 )
{
print_format();
return;
}
try
{
num_threads = Integer.parseInt(argv[1]);
join_wait = Integer.parseInt(argv[2]);
}
catch(Exception e)
{
e.printStackTrace();
print_format();
}
// convert to milliseconds
join_wait *= 1000;
// run test
new ThreadJoinTest().diff_io(argv[0], num_threads, 0, join_wait);
} // end main()
} // end class io
- relates to
-
JDK-1223814 thread join does not seem to work after a while
-
- Closed
-