java.lang.Thread的通用数组创建
Intellij IDEA正在抱怨java.lang.Thread的通用数组创建,java,android,Java,Android,Intellij IDEA正在抱怨通用数组创建 public abstract class BaseImageLoader<CacheItem> { private ImageLoaderThread[] workerThreads; public BaseImageLoader(Context context) { ... workerThreads = new ImageLoaderThread[DEFAULT_CACHE
通用数组创建
public abstract class BaseImageLoader<CacheItem>
{
private ImageLoaderThread[] workerThreads;
public BaseImageLoader(Context context)
{
...
workerThreads = new ImageLoaderThread[DEFAULT_CACHE_THREAD_POOL_SIZE];//Generic array creation error
...
}
}
ImageLoaderThread类
private class ImageLoaderThread extends Thread
{
/**
* The queue of requests to service.
*/
private final BlockingQueue<ImageData> mQueue;
/**
* Used for telling us to die.
*/
private volatile boolean mQuit = false;
/**
* Creates a new cache thread. You must call {@link #start()}
* in order to begin processing.
*
* @param queue Queue of incoming requests for triage
*/
public ImageLoaderThread(BlockingQueue<ImageData> queue)
{
mQueue = queue;
}
/**
* Forces this thread to quit immediately. If any requests are still in
* the queue, they are not guaranteed to be processed.
*/
public void quit()
{
mQuit = true;
interrupt();
}
@Override
public void run()
{
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
ImageData data;
while (true)
{
try
{
// Take a request from the queue.
data = mQueue.take();
}
catch (InterruptedException e)
{
// We may have been interrupted because it was time to quit.
if (mQuit)
{
return;
}
continue;
}
...
//other unrelated stuff
}
}
}
私有类ImageLoaderThread扩展线程
{
/**
*要服务的请求队列。
*/
私有最终阻塞队列MQUE;
/**
*用来告诉我们去死。
*/
私有易失性布尔mQuit=false;
/**
*创建新的缓存线程。必须调用{@link#start()}
*以便开始处理。
*
*@param队列用于分类的传入请求队列
*/
公共ImageLoaderThread(阻塞队列)
{
MQUE=队列;
}
/**
*强制此线程立即退出。如果仍有任何请求
*在队列中,它们不保证被处理。
*/
公开作废退出()
{
mQuit=true;
中断();
}
@凌驾
公开募捐
{
android.os.Process.setThreadPriority(Process.THREAD\u PRIORITY\u BACKGROUND);
图像数据;
while(true)
{
尝试
{
//从队列中获取请求。
data=mQueue.take();
}
捕捉(中断异常e)
{
//我们可能被打断了,因为是时候退出了。
if(mQuit)
{
回来
}
持续
}
...
//其他无关的东西
}
}
}
看看这是否有帮助:向我们展示ImageLoaderThread
。我已经添加了ImageLoaderThreadclass@pedromss行得通,hovewer我还是不明白问题出在哪里
private class ImageLoaderThread extends Thread
{
/**
* The queue of requests to service.
*/
private final BlockingQueue<ImageData> mQueue;
/**
* Used for telling us to die.
*/
private volatile boolean mQuit = false;
/**
* Creates a new cache thread. You must call {@link #start()}
* in order to begin processing.
*
* @param queue Queue of incoming requests for triage
*/
public ImageLoaderThread(BlockingQueue<ImageData> queue)
{
mQueue = queue;
}
/**
* Forces this thread to quit immediately. If any requests are still in
* the queue, they are not guaranteed to be processed.
*/
public void quit()
{
mQuit = true;
interrupt();
}
@Override
public void run()
{
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
ImageData data;
while (true)
{
try
{
// Take a request from the queue.
data = mQueue.take();
}
catch (InterruptedException e)
{
// We may have been interrupted because it was time to quit.
if (mQuit)
{
return;
}
continue;
}
...
//other unrelated stuff
}
}
}