关于ArrayList的问题(Questions about ArrayList)
我需要使用一个
ArrayList
,但我不知道如何使用普通数组做一些这些事情。1)这个:
int[][] example1 = new int[10][20];
(具有两个参数(10,20)的数组)可以使用普通数组,但是如何使用
ArrayList
执行此操作。)2)如何将列表中的int值增加1,如下所示:
example2[3][4] ++;
I need to use an
ArrayList
, but I am not sure how to do some of these things that would be possible with a normal array.1) This:
int[][] example1 = new int[10][20];
(An array with two arguments (10, 20)) is possible with normal arrays, but how to do it with an
ArrayList
.)2) How to increase the value of an int on the list by 1, like this:
example2[3][4] ++;
原文:https://stackoverflow.com/questions/18715535
最满意答案
不,这是不可能的。 这肯定是由于代码中的某些内容。
一个非常常见的情况是您的任务由于某些异常(因此非常快)而失败,但您只是看不到堆栈跟踪。 一件容易的事就是在您的任务中捕获
Throwable
并记录异常。 您也可以使用Callable
并通过返回的Future
检查任务的状态。No that's not possible. It's most certainly due to something in your code.
A very common scenario is that your tasks are failing due to some exception (and hence very quickly), but you just don't see the stack trace. One easy thing is to catch
Throwable
in your task and log the exception. You can also use aCallable
instead and check the tasks' status via the returnedFuture
.
相关问答
更多-
根据这篇文章 ,你可以调用执行者清除 。 I couldn't get anything to work so I came up with the following solution. Here is a rough overview: I created an array in the ThreadPoolExecutor that kept track of the runnables that were in the queue. Then when I needed to cancel the ...
-
从ThreadPoolExecutor中访问提交的对象(Access the submitted object from within a ThreadPoolExecutor)[2023-05-11]
不要使用execute ,使用submit ,它返回一个Future ,它是任务的句柄。 这是一些示例代码: ExecutorService service = Executors.newCachedThreadPool(); Callabletask = new Callable () { public String call() throws Exception { return "hello world"; } }; Future ThreadPoolExecutor vs ForkJoinPool:窃取子任务(ThreadPoolExecutor vs ForkJoinPool: stealing subtasks)[2024-02-09]
在ForkJoinPool ,有两种队列 - 在提交任务时基本上使用的池,以及特定于线程的池(即每个线程一个)。 从ForkJoinTask您可以调用新任务(通常是您的问题的一部分)。 这些新任务不会提供给池队列,而是提供给线程特定的任务。 因此,它们优先于池1被取/拉,就像你在同一任务中完成了所有工作一样。 此外,调用者任务似乎被阻止以完成子任务。 实际上,“阻塞时间”用于消耗子任务。 让其他线程“闲逛”而其中一个被工作淹没将是愚蠢的。 因此,“偷工作”发生了。 超越。 为了提高效率,“偷工作”从相反的界 ...不,这是不可能的。 这肯定是由于代码中的某些内容。 一个非常常见的情况是您的任务由于某些异常(因此非常快)而失败,但您只是看不到堆栈跟踪。 一件容易的事就是在您的任务中捕获Throwable并记录异常。 您也可以使用Callable并通过返回的Future检查任务的状态。 No that's not possible. It's most certainly due to something in your code. A very common scenario is that your tasks ar ...我没有看到你将你的工作提交到ThreadPoolExecutor 示例代码: executor.execute(new Runnabale() { public void run() { // your job code } }); 编辑: 我刚刚注意到你正在覆盖AsyncHttpClient的默认ThreadPoolExecuter ,因此它会在发出请求时使用它(例如get ),它应该在没有向executor显式发送任何内容的情况下工作 您还可以覆盖方法terminated ...AsyncTask不是Runnable,因此您无法真正使用它。 An AsyncTask is not a Runnable so you can't really use that.我想我做了另一个答案,因为它对同一个问题有不同的解决方案。 您只能使用ThreadPoolExecutor和Semaphore。 将使用您希望在队列中允许的最大数量创建信号量,并且在每个线程完成执行后,您将调用release(beforeExecute,即从项目中取出项目时) Semaphore semaphore = new Semaphore(1000); ThreadPoolExecutor executor = new ThreadPoolExecutor(5,10,60,TimeUnit.SECO ...检查ThreadPoolExecutor中的所有任务是否都已完成(Checking whether all tasks in ThreadPoolExecutor are completed)[2023-09-28]
yourThreadPoolExecutor.getActiveCount(); 所有任务完成后将返回0 。 yourThreadPoolExecutor.getActiveCount(); will return 0 when all tasks have completed.为什么不简单地保留一下Runnables列表? Listrunnables = new ArrayList<> (); VideoExportThread r = new VideoExportThread(gcmPath); runnables.add(r); executor.submit(r); 还要注意executor.submit(r); 返回Future - 您可以调用其isDone()方法来检查提交的任务是否仍在运行。 旁注:可能有充分的理由手动管理作业队列,但如果没有 ... 死你threadpoolexecutor(Die you threadpoolexecutor)[2023-06-12]
您可以创建ThreadPoolExecutor子类并覆盖afterExecute方法。 该方法有一个throwable参数,如果有异常,该参数将为非null。 You can create a ThreadPoolExecutor subclass and override the afterExecute method. The method has a throwable parameter that will be non-null if there was an exception.相关文章
更多- ArrayList问题
- 关于ArrayList的使用问题~~~~~~~
- 一个ArrayList里是否可以添加不同的类,一个数组里是否可以添加不同类
- Common Interview Questions
- Apache Solr questions
- 每日英语:7 Important Questions to Ask Yourself Today
- HDFS Append 设计文档的QA(Questions about the “Append Design”)
- webservice的返回值问题
- 请教两个JAVA问题
- 请问这个简单的登录界面为什么跳转老错,就是登录账户和密码都对的还跳转不到指定页面?
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。