クラスTileの何千ものインスタンスを作成しようとしています。
int length=64;
Tile tiles[][]=new Tile[length][length]
for(int y=0;y<length;y++)for(int x=0;x<length;x++)
try{tiles[x][y]=new Tile(x,y);}catch(FileNotFoundException e) {e.printStackTrace();}
新しいタイルを作成するには、0.01 ~ 0.1 秒かかります。
これへのスレッドを作成して実験しましたが、遅くなりました。
tiles=new Tile[length][length];
private static int y,x;
final CountDownLatch end=new CountDownLatch(length*length);
for( y=0;y<tiles.length;y++)for(x=0;x<tiles.length;x++)
new Thread()
{
public void run()
{
int y=new Integer(OutterClass.y),x=new Integer(OutterClass.x);
try {
tiles[x][y]=new Tile(x,y);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
end.countDown();
}
}.start();
end.await();
これをスピードアップすることはありますか?