等待几个线程中的一个完成?(Wait for one of several threads to finish?)
我正在实现一个线程池。 每个线程所需的工作是1-10秒的CPU,所以我很高兴有一个传统的工作线程池,或者我很乐意为每个工作单元生成一个新的线程。 没关系。
我想有一些方法让主控制线程知道N个工作线程中的一个何时完成其工作并准备好更多(或者是时候启动另一个)。 我看过pthread_join和pthread_cond_wait。 似乎没有办法等待N中的一个。所以我想主线程有一个变量,它用来进入睡眠并让工人将其唤醒。 如果工人不死,这似乎有效。 但是,如果它们死了,那么在工作者唤醒控制器的时间和它不能处理的时间之间会有一个窗口。
我看过英特尔的TBB,但它看起来比我需要的要复杂得多。
在Microsoft Windows中是否存在PTHREADS中的WaitForMultipleObjects的简单等价物?
I am implementing a thread pool. The work required by each thread is 1-10 seconds of CPU, so I'm happy to have a traditional thread pool with workers, or I'm happy to spawn a new thread for each unit of work. It doesn't matter.
I would like to have some way for the master control thread to know when one of the N worker threads finishes its work and is ready for more (or its time to start another). I've looked at pthread_join and pthread_cond_wait. There doesn't seem to be a way to wait for one of N. So I thought about having the master thread have a variable that it uses to go to sleep and having the workers wake it up. This seems to work if the workers don't die. However, if they die, there's a window between the time that the worker wakes up the controller and the time it dies which I don't want to deal with.
I've looked at Intel's TBB but it looks much more complicated than I need.
Is there a simple equivalent in PTHREADS to WaitForMultipleObjects in Microsoft Windows?
原文:https://stackoverflow.com/questions/4264460
最满意答案
你超越了手机/平板电脑的容量。 只是尝试以块的形式加载单元格,如下所示:
public class ReadExcelFile { ArrayList<String> list = new ArrayList<String>(); Workbook myWorkBook; // open but not close, leave it open public void OpenExcelFile() { WorkbookSettings s = null; InputStream excelContent = null; try { excelContent = this.getClass().getResourceAsStream("/com/product/sopho/lexiko.xls"); s = new WorkbookSettings(); s.setUseTemporaryFileDuringWrite(true); myWorkbook = Workbook.getWorkbook(excelContent,s); } catch(Exception e) { } // we leave it open } // close when you are done public void closeExcelFile() { if(myWorkBook != null) { myWorkBook.close(); } } // Once opened, get chunks calling ExcelKeyList(0,0,1000) .... etc private ArrayList<String> ExcelKeyList(int sheet,int startRow, int endRow) { Sheet sheet = myWorkBook.getSheet(sheet); ExcelMap(sheet); ExcelKeyList(sheet); list.clear(); for (int i=startRow; i<endRow; i++) { list.add(sheet.getCell(0,i).getContents()); } return list; } public ArrayList<String> getExcelKeyList() { return list; } }
你必须在手机爆炸之前找出推荐的块大小。
You are surpassing the phone / tablet capacity. Just try to load the cells in chunks, like this:
public class ReadExcelFile { ArrayList<String> list = new ArrayList<String>(); Workbook myWorkBook; // open but not close, leave it open public void OpenExcelFile() { WorkbookSettings s = null; InputStream excelContent = null; try { excelContent = this.getClass().getResourceAsStream("/com/product/sopho/lexiko.xls"); s = new WorkbookSettings(); s.setUseTemporaryFileDuringWrite(true); myWorkbook = Workbook.getWorkbook(excelContent,s); } catch(Exception e) { } // we leave it open } // close when you are done public void closeExcelFile() { if(myWorkBook != null) { myWorkBook.close(); } } // Once opened, get chunks calling ExcelKeyList(0,0,1000) .... etc private ArrayList<String> ExcelKeyList(int sheet,int startRow, int endRow) { Sheet sheet = myWorkBook.getSheet(sheet); ExcelMap(sheet); ExcelKeyList(sheet); list.clear(); for (int i=startRow; i<endRow; i++) { list.add(sheet.getCell(0,i).getContents()); } return list; } public ArrayList<String> getExcelKeyList() { return list; } }
You have to find out what's the recommended chunk size before the phone explodes.
相关问答
更多-
您可以使用PHPExcel保存内存。 主要有两个: 单元缓存,在开发人员文档的4.2.1节中描述, 这允许您减少从文件读取的每个单元的内存开销 Chunking,在读者用户文档的4.3节中描述 这允许您从文件中读取小范围的行和列,而不是整个工作表 You have a few options for saving memory with PHPExcel. The main two are: cell caching, described in section 4.2.1 of the developer ...
-
FileSystemObject库有一个GetExtensionName()函数,可以让生活更轻松: With CreateObject("Scripting.FileSystemObject") strExt = .GetExtensionName(ActiveWorkbook.Path) End With If StrComp(strExt, "xls", vbTextCompare) = 0 Then ' Display error End If 或者,您可以只检查工作簿中的行数: ...
-
你可以使用这个API: http://www.andykhan.com/jexcelapi/tutorial.html 您可以根据需要获取任何对象的数据。 You can use this api : http://www.andykhan.com/jexcelapi/tutorial.html And you can get data any object what you want.
-
我认为你需要打开一个线程或异步任务来从服务器下载文件。 在这个线程中,使用android.os.Handler将任何进度/结果通知给主ui线程。 I think you need to open a thread or async task to download files from server. And in this thread ,notify any progress /result to main ui thread using android.os.Handler.
-
你有什么问题? 你有任何错误吗? 尝试添加一些侦听器以排除问题。 package { import flash.display.Sprite; import flash.events.*; import flash.net.*; public class URLLoaderExample extends Sprite { public function URLLoaderExample() { var loader:URLLoader ...
-
xls文件可以解释为文本文件,作为csv文件(带逗号的文本)。 但XLSX却与众不同。 如果你用.zip替换.xlsx,你会看到(winzip,winrar。atc)它有很多内部文件......它是一个Office Open XML SpreadsheetML文件格式。 https://msdn.microsoft.com/en-us/library/dd922181(v=office.12).aspx 要打开XLSX文件,请尝试另一个连接String,如下所示: Dim cnn As New OleDb. ...
-
Apache Poi更新xls文件(Apache Poi update xls file)[2022-02-12]
您可能需要在更改单元格的值之前创建单元格。 如果一个单元格没有值,它就“不存在”,所以你需要创建它然后设置它的值。 您可以尝试使用getCell()和mising rowPolicy来尝试获取一个单元格(如果它们当前不是一个单元格),如下所示: myRow.getCell(7, Row.CREATE_NULL_AS_BLANK);//Should create cell if it is currently blank 获得单元后,尝试设置它的值,就像你一直在做的那样。 或者,如果您有一个细胞,请尝试事先 ... -
你超越了手机/平板电脑的容量。 只是尝试以块的形式加载单元格,如下所示: public class ReadExcelFile { ArrayList
list = new ArrayList (); Workbook myWorkBook; // open but not close, leave it open public void OpenExcelF ... -
android xls文件支持(android xls file support)[2023-11-20]
我在我的Android项目中使用了jExcel,它工作正常。 I used jExcel in my Android project and it worked fine. -
对于这个特定的Coursera练习,而不是一般情况,你可以不使用read_excel函数中的整个URL,而只使用'Energy Indicators.xls' energy = pd.read_excel('Energy Indicators.xls',...) For this specific Coursera exercise, and not as a general case, you can use not the whole URL in read_excel function, but j ...