你能帮助我multithreading
,例如我如何让这个方法在两个线程中运行。
/**
* returns 16 bytes
*/
private byte[] keyStream() {
nextState();
final byte[] s = new byte[16];
/* unroll */
int x = X[6] ^ X[3] >>> 16 ^ X[1] << 16;
s[0] = (byte) (x >>> 24);
s[1] = (byte) (x >> 16);
s[2] = (byte) (x >> 8);
s[3] = (byte) x;
x = X[4] ^ X[1] >>> 16 ^ X[7] << 16;
s[4] = (byte) (x >>> 24);
s[5] = (byte) (x >> 16);
s[6] = (byte) (x >> 8);
s[7] = (byte) x;
x = X[2] ^ X[7] >>> 16 ^ X[5] << 16;
s[8] = (byte) (x >>> 24);
s[9] = (byte) (x >> 16);
s[10] = (byte) (x >> 8);
s[11] = (byte) x;
x = X[0] ^ X[5] >>> 16 ^ X[3] << 16;
s[12] = (byte) (x >>> 24);
s[13] = (byte) (x >> 16);
s[14] = (byte) (x >> 8);
s[15] = (byte) x;
return s;
}
答案 0 :(得分:2)
您可以简单地创建一个类,实现Runnable
并覆盖run
函数,如下所示:
class MyRunnable implements Runnable{
public void run(){
byte[] retVal = keyStream();
}
/**
* returns 16 bytes
*/
private byte[] keyStream() {
// function implementation
}
}
您可以通过某种方式使用它,例如:
Thread myThread1= new Thread(new MyRunnable());
Thread myThread2= new Thread(new MyRunnable());
myThread1.start();
myThread2.start();