loopinterchanged.java
来自「java threads 3th源码,包括各个章节的源代码」· Java 代码 · 共 48 行
JAVA
48 行
package javathreads.examples.ch15.example10;import javathreads.examples.ch15.*;public class LoopInterchanged implements ScaleTester { private float lookupValues[][]; private int nRows, nCols, nThreads; private class LoopInterchangedHandler extends PoolLoopHandler { LoopInterchangedHandler(int nc, int nt) { super(0, nc, nt); } public void loopDoRange(int start, int end) { for (int i = start; i < end; i++) { lookupValues[0][i] = 0; } for (int i = start; i < end; i++) { for (int j = 1; j < nRows; j++) { float sinValue = (float)Math.sin((i % 360)*Math.PI/180.0); lookupValues[j][i] = sinValue * (float)i / 180.0f; lookupValues[j][i] += lookupValues[j-1][i]*(float)j/180.0f; } } } } public void init(int nRows, int nCols, int nThreads) { this.nRows = nRows; this.nCols = nCols; this.nThreads = nThreads; lookupValues = new float[nRows][]; for (int j = 0; j < nRows; j++) { lookupValues[j] = new float[nCols]; } } public float[][] doCalc() { LoopInterchangedHandler loop = new LoopInterchangedHandler(nCols, nThreads); loop.loopProcess(); return lookupValues; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?