CompletionException-100

问题描述:关于分布式Hadoop在WINDOWS上操作问题 本篇文章给大家谈谈一个有趣的事情,以及一个有趣的事情,希望对各位有所帮助,不要忘了收藏本站喔。

怎么获取ftp的路径

CompletionException-100的相关图片

若在windows的Eclipse工程中直接启动mapreduc程序,需要先把hadoop集群的配置目录下的xml都拷贝到src目录下,让程序自动读取集群的地址后去进行分布式运行(您也可以自己写java代码去设置job的configuration属性)。

若不拷贝,工程中bin目录没有完整的xml配置文件,则windows执行的mapreduce程序全部通过本机的jvm执行,作业名也是带有“local"字眼的作业,如 job_local2062122004_0001。 这不是真正的分布式运行mapreduce程序。

估计得研究org.apache.hadoop.conf.Configuration的源码,反正xml配置文件会影响执行mapreduce使用的文件系统是本机的windows文件系统还是远程的hdfs系统; 还有影响执行mapreduce的mapper和reducer的是本机的jvm还是集群里面机器的jvm。

二、 本文的结论

第一点就是: windows上执行mapreduce,必须打jar包到所有slave节点才能正确分布式运行mapreduce程序。(我有个需求是要windows上触发一个mapreduce分布式运行)

第二点就是: Linux上,只需拷贝jar文件到集群master上,执行命令hadoop jarPackage.jar MainClassName即可分布式运行mapreduce程序。

第三点就是: 推荐使用附一,实现了自动打jar包并上传,分布式执行的mapreduce程序。

附一、 推荐使用此方法:实现了自动打jar包并上传,分布式执行的mapreduce程序:

请先参考博文五篇:

Hadoop作业提交分析(一)~~(五)

引用博文的附件中EJob.java到你的工程中,然后main中添加如下方法和代码。

public static File createPack() throws IOException {。

File jarFile = EJob.createTempJar("bin");。

ClassLoader classLoader = EJob.getClassLoader();。

Thread.currentThread().setContextClassLoader(classLoader);。

return jarFile;。

在作业启动代码中使用打包:

Job job = Job.getInstance(conf, "testAnaAction");。

添加:

String jarPath = createPack().getPath();。

job.setJar(jarPath);。

即可实现直接run as java application 在windows跑分布式的mapreduce程序,不用手工上传jar文件。

附二、得出结论的测试过程

(未有空看书,只能通过愚笨的测试方法得出结论了)

一. 直接通过windows上Eclipse右击main程序的java文件,然后"run as application"或选择hadoop插件"run on hadoop"来触发执行MapReduce程序的测试。

1,如果不打jar包到进集群任意linux机器上,它报错如下:

[work] 2012-06-25 15:42:47,360 - org.apache.hadoop.mapreduce.Job -10244 [main] INFO org.apache.hadoop.mapreduce.Job - map 0% reduce 0%。

[work] 2012-06-25 15:42:52,223 - org.apache.hadoop.mapreduce.Job -15107 [main] INFO org.apache.hadoop.mapreduce.Job - Task Id : attempt_1403517983686_0056_m_000000_0, Status : FAILED。

Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class bookCount.BookCount$BookCountMapper not found。

at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1720)。

at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:186)。

at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:721)。

at org.apache.hadoop.mapred.MapTask.run(MapTask.java:339)。

at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:162)。

at java.security.AccessController.doPrivileged(Native Method)。

at javax.security.auth.Subject.doAs(Subject.java:415)。

at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491)。

at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:157)。

Caused by: java.lang.ClassNotFoundException: Class bookCount.BookCount$BookCountMapper not found。

at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1626)。

at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1718)。

... 8 more

# Error:后重复三次

2012-06-25 15:44:53,234 - org.apache.hadoop.mapreduce.Job -37813 [main] INFO org.apache.hadoop.mapreduce.Job - map 100% reduce 100%。

现象就是:报错,无进度,无运行结果。

2,拷贝jar包到“只是”集群master的$HADOOP_HOME/share/hadoop/mapreduce/目录上,直接通过windows的eclipse "run as application"和通过hadoop插件"run on hadoop"来触发执行,它报错同上。

现象就是:报错,无进度,无运行结果。

3,拷贝jar包到集群某些slave的$HADOOP_HOME/share/hadoop/mapreduce/目录上,直接通过windows的eclipse "run as application"和通过hadoop插件"run on hadoop"来触发执行。

和报错:

Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class bookCount.BookCount$BookCountMapper not found。

at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1720)。

at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:186)。

和报错:

Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class bookCount.BookCount$BookCountReducer not found。

现象就是:有报错,但仍然有进度,有运行结果。

4,拷贝jar包到集群所有slave的$HADOOP_HOME/share/hadoop/mapreduce/目录上,直接通过windows的eclipse "run as application"和通过hadoop插件"run on hadoop"来触发执行:

现象就是:无报错,有进度,有运行结果。

第一点结论就是: windows上执行mapreduce,必须打jar包到所有slave节点才能正确分布式运行mapreduce程序。

二 在Linux上的通过以下命令触发MapReduce程序的测试。

hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/bookCount.jar bookCount.BookCount。

1,只拷贝到master,在master上执行。

现象就是:无报错,有进度,有运行结果。

2,拷贝随便一个slave节点,在slave上执行。

现象就是:无报错,有进度,有运行结果。

但某些节点上运行会报错如下,且运行结果。:

14/06/25 16:44:02 INFO mapreduce.JobSubmitter: Cleaning up the staging area /tmp/hadoop-yarn/staging/hduser/.staging/job_1403517983686_0071。

Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH。

at org.apache.hadoop.mapreduce.v2.util.MRApps.setMRFrameworkClasspath(MRApps.java:157)。

at org.apache.hadoop.mapreduce.v2.util.MRApps.setClasspath(MRApps.java:198)。

at org.apache.hadoop.mapred.YARNRunner.createApplicationSubmissionContext(YARNRunner.java:443)。

at org.apache.hadoop.mapred.YARNRunner.submitJob(YARNRunner.java:283)。

at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:415)。

at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1268)。

at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1265)。

at java.security.AccessController.doPrivileged(Native Method)。

at javax.security.auth.Subject.doAs(Subject.java:415)。

at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491)。

at org.apache.hadoop.mapreduce.Job.submit(Job.java:1265)。

at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1286)。

at com.etrans.anaSpeed.AnaActionMr.run(AnaActionMr.java:207)。

at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)。

at com.etrans.anaSpeed.AnaActionMr.main(AnaActionMr.java:44)。

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)。

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)。

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)。

at java.lang.reflect.Method.invoke(Method.java:606)。

at org.apache.hadoop.util.RunJar.main(RunJar.java:212)。

第二点结论就是: Linux上,只需拷贝jar文件到集群master上,执行命令hadoop jarPackage.jar MainClassName即可分布式运行mapreduce程序。

一个Java中关于抛出异常的问题的相关图片

一个Java中关于抛出异常的问题

问一下,你是想做ftp上传下载么?

首先你需要安装一个ftp服务端程序,启动起来,然后下载一个ftp客户端程序,测试能不能连接,首先这一块儿需要测试通过。

代码ftp上传下载

2.1 上传代码:

import java.io.File;。

import java.io.FileInputStream;。

import org.apache.commons.net.ftp.FTPClient;。

import org.apache.commons.net.ftp.FTPReply;。

public class test {。

private FTPClient ftp;。

/**

* @param path 上传到ftp服务器哪个路径下。

* @param addr 地址。

* @param port 端口号。

* @param username 用户名。

* @param password 密码。

* @return

* @throws Exception。

*/

private boolean connect(String path,String addr,int port,String username,String password) throws Exception {。

boolean result = false;。

ftp = new FTPClient();。

int reply;

ftp.connect(addr,port);。

ftp.login(username,password);。

ftp.setFileType(FTPClient.BINARY_FILE_TYPE);。

reply = ftp.getReplyCode();。

if (!FTPReply.isPositiveCompletion(reply)) {。

ftp.disconnect();。

return result;

ftp.changeWorkingDirectory(path);。

result = true;

return result;

/**

* @param file 上传的文件或文件夹。

* @throws Exception。

*/

private void upload(File file) throws Exception{。

if(file.isDirectory()){。

ftp.makeDirectory(file.getName());。

ftp.changeWorkingDirectory(file.getName());。

String[] files = file.list();。

for (int i = 0; i < files.length; i++) {。

File file1 = new File(file.getPath()+"\\"+files[i] );。

if(file1.isDirectory()){。

upload(file1);

ftp.changeToParentDirectory();。

}else{

File file2 = new File(file.getPath()+"\\"+files[i]);。

FileInputStream input = new FileInputStream(file2);。

ftp.storeFile(file2.getName(), input);。

input.close();

}else{

File file2 = new File(file.getPath());。

FileInputStream input = new FileInputStream(file2);。

ftp.storeFile(file2.getName(), input);。

input.close();

public static void main(String[] args) throws Exception{。

test t = new test();。

t.connect("", "localhost", 21, "yhh", "yhhazr");。

File file = new File("e:\\uploadify");。

t.upload(file);。

2.2 下载代码

这里没有用到filter,如果用filter就可以过滤想要的文件。

public class Ftp {。

/**

* @param args。

*/

public static void main(String[] args) {。

// TODO Auto-generated method stub。

Ftp ftp = new Ftp();。

String hostname = "www.strawberry.com";。

Integer port = 21;。

String username = "username";。

String password = "password";。

String remote = "/c.txt";。

String local = "/home/tin/LeonChen/FTP/";。

try {

ftp.connect(hostname, port, username, password);。

System.out.println("接收状态:"+ftp.download(remote, local));。

ftp.disconnect();。

} catch (IOException e) {。

// TODO Auto-generated catch block。

e.printStackTrace();。

}

}

private FTPClient ftpClient = new FTPClient();。

/*

* * 连接到FTP服务器 。

* * @param hostname 主机名 。

* * @param port 端口 。

* * @param username 用户名 。

* * @param password 密码 。

* * @return 是否连接成功 。

* * @throws IOException。

*/

private boolean connect(String hostname, int port, String username,。

String password) throws IOException {。

ftpClient.connect(hostname, port);。

ftpClient.setControlEncoding("UTF-8");。

if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {。

if (ftpClient.login(username, password)) {。

return true;。

}

}

disconnect();。

return false;。

}

/*

* 从FTP服务器上下载文件,支持断点续传,上传百分比汇报。

*

* @param remote 远程文件路径。

*

* @param local 本地文件路径。

*

* @return 上传的状态。

*

* @throws IOException。

*/

public DownloadStatus download(String remote, String local)。

throws IOException {。

// 设置被动模式。

ftpClient.enterLocalPassiveMode();。

// 设置以二进制方式传输。

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);。

DownloadStatus result;。

// 检查远程文件是否存在。

FTPFile[] files = ftpClient.listFiles(new String(remote。

.getBytes("UTF-8"), "iso-8859-1"));。

if (files.length != 1) {。

System.out.println("远程文件不存在");。

return DownloadStatus.Remote_File_Noexist;。

}

long lRemoteSize = files[0].getSize();。

String fildName = files[0].getName();。

// 本地存在文件,进行断点下载。

File f = new File(local+fildName);。

if (f.exists()) {。

long localSize = f.length();。

if (localSize >= lRemoteSize) {。

System.out.println("本地文件大于远程文件,下载中止");。

return DownloadStatus.Local_Bigger_Remote;。

}

// 进行断点续传,并记录状态。

FileOutputStream out = new FileOutputStream(f, true);。

ftpClient.setRestartOffset(localSize);。

InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("UTF-8"), "iso-8859-1"));。

byte[] bytes = new byte[1024];。

long step = lRemoteSize / 100;。

long process = localSize / step;。

int c;。

while ((c = in.read(bytes)) != -1) {。

out.write(bytes, 0, c);。

localSize += c;。

long nowProcess = localSize / step;。

if (nowProcess > process) {。

process = nowProcess;。

if (process % 10 == 0)。

System.out.println("下载进度:" + process);。

// TODO 更新文件下载进度,值存放在process变量中。

}。

}

in.close();。

out.close();。

boolean isDo = ftpClient.completePendingCommand();。

if (isDo) {。

result = DownloadStatus.Download_From_Break_Success;。

} else {。

result = DownloadStatus.Download_From_Break_Failed;。

}

} else {。

OutputStream out = new FileOutputStream(f);。

InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("UTF-8"), "iso-8859-1"));。

byte[] bytes = new byte[1024];。

long step = lRemoteSize / 100;。

long process = 0;。

long localSize = 0L;。

int c;。

while ((c = in.read(bytes)) != -1) {。

out.write(bytes, 0, c);。

localSize += c;。

long nowProcess = localSize / step;。

if (nowProcess > process) {。

process = nowProcess;。

if (process % 10 == 0)。

System.out.println("下载进度:" + process);。

// TODO 更新文件下载进度,值存放在process变量中。

}。

}

in.close();。

out.close();。

boolean upNewStatus = ftpClient.completePendingCommand();。

if (upNewStatus) {。

result = DownloadStatus.Download_New_Success;。

} else {。

result = DownloadStatus.Download_New_Failed;。

}

}

return result;。

}

private void disconnect() throws IOException {。

if (ftpClient.isConnected()) {。

ftpClient.disconnect();。

}

}

.NET平台下几种SOCKET模型的简要性能供参考的相关图片

.NET平台下几种SOCKET模型的简要性能供参考

1 引子

try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解。不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单、听话。不信?那你看看下面的代码,“猜猜”它执行后的结果会是什么?不要往后看答案、也不许执行代码看真正答案哦。如果你的答案是正确,那么这篇文章你就不用浪费时间看啦。

public class TestException。

public TestException()。

boolean testEx() throws Exception。

boolean ret = true;。

try

ret = testEx1();。

catch (Exception e)。

System.out.println("testEx, catch exception");。

ret = false;

throw e;

finally

System.out.println("testEx, finally; return value=" + ret);。

return ret;

boolean testEx1() throws Exception。

boolean ret = true;。

try

ret = testEx2();。

if (!ret)

return false;

System.out.println("testEx1, at the end of try");。

return ret;

catch (Exception e)。

System.out.println("testEx1, catch exception");。

ret = false;

throw e;

finally

System.out.println("testEx1, finally; return value=" + ret);。

return ret;

boolean testEx2() throws Exception。

boolean ret = true;。

try

int b = 12;

int c;

for (int i = 2; i >= -2; i--)。

c = b / i;

System.out.println("i=" + i);。

return true;

catch (Exception e)。

System.out.println("testEx2, catch exception");。

ret = false;

throw e;

finally

System.out.println("testEx2, finally; return value=" + ret);。

return ret;

public static void main(String[] args)。

TestException testException1 = new TestException();。

try

testException1.testEx();。

catch (Exception e)。

e.printStackTrace();。

你的答案是什么?是下面的答案吗?

i=2

i=1

testEx2, catch exception。

testEx2, finally; return value=false。

testEx1, catch exception。

testEx1, finally; return value=false。

testEx, catch exception。

testEx, finally; return value=false。

如果你的答案真的如上面所说,那么你错啦。^_^,那就建议你仔细看一看这篇文章或者拿上面的代码按各种不同的情况修改、执行、测试,你会发现有很多事情不是原来想象中的那么简单的。

现在公布正确答案:

i=2

i=1

testEx2, catch exception。

testEx2, finally; return value=false。

testEx1, finally; return value=false。

testEx, finally; return value=false。

2 基础知识

2.1 相关概念

例外是在程序运行过程中发生的异常事件,比如除0溢出、数组越界、文件找不到等,这些事件的发生将阻止程序的正常运行。为了加强程序的鲁棒性,程序设计时,必须考虑到可能发生的异常事件并做出相应的处理。C语言中,通过使用if语句来判断是否出现了例外,同时,调用函数通过被调用函数的返回值感知在被调用函数中产生的例外事件并进行处理。全程变量ErroNo常常用来反映一个异常事件的类型。但是,这种错误处理机制会导致不少问题。

Java通过面向对象的方法来处理例外。在一个方法的运行过程中,如果发生了例外,则这个方法生成代表该例外的一个对象,并把它交给运行时系统,运行时系统寻找相应的代码来处理这一例外。我们把生成例外对象并把它提交给运行时系统的过程称为抛弃(throw)一个例外。运行时系统在方法的调用栈中查找,从生成例外的方法开始进行回朔,直到找到包含相应例外处理的方法为止,这一个过程称为捕获(catch)一个例外。

2.2 Throwable类及其子类。

用面向对象的方法处理例外,就必须建立类的层次。类 Throwable位于这一类层次的最顶层,只有它的后代才可以做为一个例外被抛弃。图1表示了例外处理的类层次。

从图中可以看出,类Throwable有两个直接子类:Error和Exception。Error类对象(如动态连接错误等),由Java虚拟机生成并抛弃(通常,Java程序不对这类例外进行处理);Exception类对象是Java程序处理或抛弃的对象。它有各种不同的子类分别对应于不同类型的例外。其中类RuntimeException代表运行时由Java虚拟机生成的例外,如算术运算例外ArithmeticException(由除0错等导致)、数组越界例外ArrayIndexOutOfBoundsException等;其它则为非运行时例外,如输入输出例外IOException等。Java编译器要求Java程序必须捕获或声明所有的非运行时例外,但对运行时例外可以不做处理。

2.3 异常处理关键字

Java的异常处理是通过5个关键字来实现的:try,catch,throw,throws,finally。JB的在线帮助中对这几个关键字是这样解释的:

Throws: Lists the exceptions a method could throw.。

Throw: Transfers control of the method to the exception handler.。

Try: Opening exception-handling statement.。

Catch: Captures the exception.。

Finally: Runs its code before terminating the program.。

2.3.1 try语句

try语句用大括号{}指定了一段代码,该段代码可能会抛弃一个或多个例外。

2.3.2 catch语句

catch语句的参数类似于方法的声明,包括一个例外类型和一个例外对象。例外类型必须为Throwable类的子类,它指明了catch语句所处理的例外类型,例外对象则由运行时系统在try所指定的代码块中生成并被捕获,大括号中包含对象的处理,其中可以调用对象的方法。

catch语句可以有多个,分别处理不同类的例外。Java运行时系统从上到下分别对每个catch语句处理的例外类型进行检测,直到找到类型相匹配的catch语句为止。这里,类型匹配指catch所处理的例外类型与生成的例外对象的类型完全一致或者是它的父类,因此,catch语句的排列顺序应该是从特殊到一般。

也可以用一个catch语句处理多个例外类型,这时它的例外类型参数应该是这多个例外类型的父类,程序设计中要根据具体的情况来选择catch语句的例外处理类型。

2.3.3 finally语句 。

try所限定的代码中,当抛弃一个例外时,其后的代码不会被执行。通过finally语句可以指定一块代码。无论try所指定的程序块中抛弃或不抛弃例外,也无论catch语句的例外类型是否与所抛弃的例外的类型一致,finally所指定的代码都要被执行,它提供了统一的出口。通常在finally语句中可以进行资源的清除工作。如关闭打开的文件等。

2.3.4 throws语句 。

throws总是出现在一个函数头中,用来标明该成员函数可能抛出的各种异常。对大多数Exception子类来说,Java 编译器会强迫你声明在一个成员函数中抛出的异常的类型。如果异常的类型是Error或 RuntimeException, 或它们的子类,这个规则不起作用, 因为这在程序的正常部分中是不期待出现的。 如果你想明确地抛出一个RuntimeException,你必须用throws语句来声明它的类型。

2.3.5 throw语句

throw总是出现在函数体中,用来抛出一个异常。程序会在throw语句后立即终止,它后面的语句执行不到,然后在包含它的所有try块中(可能在上层调用函数中)从里向外寻找含有与其匹配的catch子句的try块。

3 关键字及其中语句流程详解

3.1 try的嵌套

你可以在一个成员函数调用的外面写一个try语句,在这个成员函数内部,写另一个try语句保护其他代码。每当遇到一个try语句,异常的框架就放到堆栈上面,直到所有的try语句都完成。如果下一级的try语句没有对某种异常进行处理,堆栈就会展开,直到遇到有处理这种异常的try语句。下面是一个try语句嵌套的例子。

class MultiNest {。

static void procedure() {。

try {

int a = 0;

int b = 42/a;

} catch(java.lang.ArithmeticException e) {。

System.out.println("in procedure, catch ArithmeticException: " + e);。

public static void main(String args[]) {。

try {

procedure();

} catch(java.lang. Exception e) {。

System.out.println("in main, catch Exception: " + e);。

这个例子执行的结果为:

in procedure, catch ArithmeticException: java.lang.ArithmeticException: / by zero。

成员函数procedure里有自己的try/catch控制,所以main不用去处理 ArrayIndexOutOfBoundsException;当然如果如同最开始我们做测试的例子一样,在procedure中catch到异常时使用throw e;语句将异常抛出,那么main当然还是能够捕捉并处理这个procedure抛出来的异常。例如在procedure函数的catch中的System.out语句后面增加throw e;语句之后,执行结果就变为:

in procedure, catch ArithmeticException: java.lang.ArithmeticException: / by zero。

in main, catch Exception: java.lang.ArithmeticException: / by zero。

3.2 try-catch程序块的执行流程以及执行结果。

相对于try-catch-finally程序块而言,try-catch的执行流程以及执行结果还是比较简单的。

首先执行的是try语句块中的语句,这时可能会有以下三种情况:

1.如果try块中所有语句正常执行完毕,那么就不会有其他的“动做”被执行,整个try-catch程序块正常完成。

2.如果try语句块在执行过程中碰到异常V,这时又分为两种情况进行处理:

-->如果异常V能够被与try相应的catch块catch到,那么第一个catch到这个异常的catch块(也是离try最近的一个与异常V匹配的catch块)将被执行;如果catch块执行正常,那么try-catch程序块的结果就是“正常完成”;如果该catch块由于原因R突然中止,那么try-catch程序块的结果就是“由于原因R突然中止(completes abruptly)”。

-->如果异常V没有catch块与之匹配,那么这个try-catch程序块的结果就是“由于抛出异常V而突然中止(completes abruptly)”。

3. 如果try由于其他原因R突然中止(completes abruptly),那么这个try-catch程序块的结果就是“由于原因R突然中止(completes abruptly)”。

3.3 try-catch-finally程序块的执行流程以及执行结果。

try-catch-finally程序块的执行流程以及执行结果比较复杂。

首先执行的是try语句块中的语句,这时可能会有以下三种情况:

1.如果try块中所有语句正常执行完毕,那么finally块的居于就会被执行,这时分为以下两种情况:

-->如果finally块执行顺利,那么整个try-catch-finally程序块正常完成。

-->如果finally块由于原因R突然中止,那么try-catch-finally程序块的结局是“由于原因R突然中止(completes abruptly)”

2.如果try语句块在执行过程中碰到异常V,这时又分为两种情况进行处理:

-->如果异常V能够被与try相应的catch块catch到,那么第一个catch到这个异常的catch块(也是离try最近的一个与异常V匹配的catch块)将被执行;这时就会有两种执行结果:

-->如果catch块执行正常,那么finally块将会被执行,这时分为两种情况:

-->如果finally块执行顺利,那么整个try-catch-finally程序块正常完成。

-->如果finally块由于原因R突然中止,那么try-catch-finally程序块的结局是“由于原因R突然中止(completes abruptly)”

-->如果catch块由于原因R突然中止,那么finally模块将被执行,分为两种情况:

-->如果如果finally块执行顺利,那么整个try-catch-finally程序块的结局是“由于原因R突然中止(completes abruptly)”。

-->如果finally块由于原因S突然中止,那么整个try-catch-finally程序块的结局是“由于原因S突然中止(completes abruptly)”,原因R将被抛弃。

(注意,这里就正好和我们的例子相符合,虽然我们在testEx2中使用throw e抛出了异常,但是由于testEx2中有finally块,而finally块的执行结果是complete abruptly的(别小看这个用得最多的return,它也是一种导致complete abruptly的原因之一啊——后文中有关于导致complete abruptly的原因分析),所以整个try-catch-finally程序块的结果是“complete abruptly”,所以在testEx1中调用testEx2时是捕捉不到testEx1中抛出的那个异常的,而只能将finally中的return结果获取到。

如果在你的代码中期望通过捕捉被调用的下级函数的异常来给定返回值,那么一定要注意你所调用的下级函数中的finally语句,它有可能会使你throw出来的异常并不能真正被上级调用函数可见的。当然这种情况是可以避免的,以testEx2为例:如果你一定要使用finally而且又要将catch中throw的e在testEx1中被捕获到,那么你去掉testEx2中的finally中的return就可以了。

这个事情已经在OMC2.0的MIB中出现过啦:服务器的异常不能完全被反馈到客户端。)

-->如果异常V没有catch块与之匹配,那么finally模块将被执行,分为两种情况:

-->如果finally块执行顺利,那么整个try-catch-finally程序块的结局就是“由于抛出异常V而突然中止(completes abruptly)”。

-->如果finally块由于原因S突然中止,那么整个try-catch-finally程序块的结局是“由于原因S突然中止(completes abruptly)”,异常V将被抛弃。

3.如果try由于其他原因R突然中止(completes abruptly),那么finally块被执行,分为两种情况:

-->如果finally块执行顺利,那么整个try-catch-finally程序块的结局是“由于原因R突然中止(completes abruptly)”。

-->如果finally块由于原因S突然中止,那么整个try-catch-finally程序块的结局是“由于原因S突然中止(completes abruptly)”,原因R将被抛弃。

3.4 try-catch-finally程序块中的return。

从上面的try-catch-finally程序块的执行流程以及执行结果一节中可以看出无论try或catch中发生了什么情况,finally都是会被执行的,那么写在try或者catch中的return语句也就不会真正的从该函数中跳出了,它的作用在这种情况下就变成了将控制权(语句流程)转到finally块中;这种情况下一定要注意返回值的处理。

例如,在try或者catch中return false了,而在finally中又return true,那么这种情况下不要期待你的try或者catch中的return false的返回值false被上级调用函数获取到,上级调用函数能够获取到的只是finally中的返回值,因为try或者catch中的return语句只是转移控制权的作用。

3.5 如何抛出异常

如果你知道你写的某个函数有可能抛出异常,而你又不想在这个函数中对异常进行处理,只是想把它抛出去让调用这个函数的上级调用函数进行处理,那么有两种方式可供选择:

第一种方式:直接在函数头中throws SomeException,函数体中不需要try/catch。比如将最开始的例子中的testEx2改为下面的方式,那么testEx1就能捕捉到testEx2抛出的异常了。

boolean testEx2() throws Exception{。

boolean ret = true;。

int b=12;

int c;

for (int i=2;i>=-2;i--){。

c=b/i;

System.out.println("i="+i);。

return true;

第二种方式:使用try/catch,在catch中进行一定的处理之后(如果有必要的话)抛出某种异常。例如上面的testEx2改为下面的方式,testEx1也能捕获到它抛出的异常:

boolean testEx2() throws Exception{。

boolean ret = true;。

try{

int b=12;

int c;

for (int i=2;i>=-2;i--){。

c=b/i;

System.out.println("i="+i);。

return true;

}catch (Exception e){。

System.out.println("testEx2, catch exception");。

Throw e;

第三种方法:使用try/catch/finally,在catch中进行一定的处理之后(如果有必要的话)抛出某种异常。例如上面的testEx2改为下面的方式,testEx1也能捕获到它抛出的异常:

boolean testEx2() throws Exception{。

boolean ret = true;。

try{

int b=12;

int c;

for (int i=2;i>=-2;i--){。

c=b/i;

System.out.println("i="+i);。

throw new Exception("aaa");。

return true;

}catch (java.lang.ArithmeticException e){。

System.out.println("testEx2, catch exception");。

ret = false;

throw new Exception("aaa");。

}finally{

System.out.println("testEx2, finally; return value="+ret);。

4 关于abrupt completion。

前面提到了complete abruptly(暂且理解为“突然中止”或者“异常结束”吧),它主要包含了两种大的情形:abrupt completion of expressions and statements,下面就分两种情况进行解释。

4.1 Normal and Abrupt Completion of Evaluation。

每一个表达式(expression)都有一种使得其包含的计算得以一步步进行的正常模式,如果每一步计算都被执行且没有异常抛出,那么就称这个表达式“正常结束(complete normally)”;如果这个表达式的计算抛出了异常,就称为“异常结束(complete abruptly)”。异常结束通常有一个相关联的原因(associated reason),通常也就是抛出一个异常V。

与表达式、操作符相关的运行期异常有:

-->A class instance creation expression, array creation expression , or string concatenation operatior expression throws an OutOfMemoryError if there is insufficient memory available. 。

-->An array creation expression throws a NegativeArraySizeException if the value of any dimension expression is less than zero. 。

-->A field access throws a NullPointerException if the value of the object reference expression is null. 。

-->A method invocation expression that invokes an instance method throws a NullPointerException if the target reference is null. 。

-->An array access throws a NullPointerException if the value of the array reference expression is null. 。

-->An array access throws an ArrayIndexOutOfBoundsException if the value of the array index expression is negative or greater than or equal to the length of the array. 。

-->A cast throws a ClassCastException if a cast is found to be impermissible at run time. 。

-->An integer division or integer remainder operator throws an ArithmeticException if the value of the right-hand operand expression is zero. 。

-->An assignment to an array component of reference type throws an ArrayStoreException when the value to be assigned is not compatible with the component type of the array.。

4.2 Normal and Abrupt Completion of Statements 。

正常情况我们就不多说了,在这里主要是列出了abrupt completion的几种情况:

-->break, continue, and return 语句将导致控制权的转换,从而使得statements不能正常地、完整地执行。

-->某些表达式的计算也可能从java虚拟机抛出异常,这些表达式在上一小节中已经总结过了;一个显式的的throw语句也将导致异常的抛出。抛出异常也是导致控制权的转换的原因(或者说是阻止statement正常结束的原因)。

如果上述事件发生了,那么这些statement就有可能使得其正常情况下应该都执行的语句不能完全被执行到,那么这些statement也就是被称为是complete abruptly. 。

导致abrupt completion的几种原因:

-->A break with no label 。

-->A break with a given label 。

-->A continue with no label 。

-->A continue with a given label 。

-->A return with no value 。

-->A return with a given value A 。

-->throw with a given value, including exceptions thrown by the Java virtual machine。

5 关于我们的编程的一点建议

弄清楚try-catch-finally的执行情况后我们才能正确使用它。

如果我们使用的是try-catch-finally语句块,而我们又需要保证有异常时能够抛出异常,那么在finally语句中就不要使用return语句了(finally语句块的最重要的作用应该是释放申请的资源),因为finally中的return语句会导致我们的throw e被抛弃,在这个try-catch-finally的外面将只能看到finally中的返回值(除非在finally中抛出异常)。(我们需要记住:不仅throw语句是abrupt completion 的原因,return、break、continue等这些看起来很正常的语句也是导致abrupt completion的原因。)

eclipse运行hadoop错误如下 ClassNotFoundException:org.apache.hadoop.io.nativeio.NativeIO$POSIX$Stat的相关图片

eclipse运行hadoop错误如下 ClassNotFoundException:org.apache.hadoop.io.nativeio.NativeIO$POSIX$Stat

1.Socket + Threads/ThreadPool大概性能:小于1500个连接 实现:Accept一个Socket,就交给一个线程去管理,比较笨,但也比较有效,因为是同步方式,控制起来很方便。高级点的,就是交给一个线程池去管理,线程池由系统自动托管,省去了开销线程的时间。一般小型项目,用这个完全足够,开发也简单。但要注意,如果若干Socket长时间占用线程池中的线程,同时其它连接数又比较多,很容易出现提示说你没有足够的线程供使用。呵呵,让Socket少做点事,少占用时间,换一个快点的CPU是不错的方式。另外,如果有一些比较好的第三方线程池组件,也可以选择使用,比如SmartThreadPool。2.Socket + Select大概性能:大于1500个连接后性能下降 实现:Select是很常用的一种模型。是在阻塞功能中轮询一个或多个Socket,将要处理的Socket放到一个IList中,当Select轮询结束后,然后我们再自己处理这个IList中的Socket。具体的用法可以看一下MSDN。Select的效率并不能说是高的,因为当队列中待处理的Socket比较多的时候,处理最后几个Socket相当于要遍历所有前面的Socket,非常不划算的.3.Socket + Asynchronous大概性能:约7500个客户端连接 实现:BeginXXXX,EndXXXX,再熟悉不过了吧。异步Socket归根到底,还是用的线程池技术,用线程池来处理异步IO。这就又引出个问题,.NET的线程池又是用的什么实现方式,以前看过有人说,.NET的线程池是用的完成端口来实现的,我不知道这样的说法是不是正确,从查到的资料中也没有办法确认(希望这点有朋友可以告诉我)。异步Socket对于程序的处理流程来说比同步复杂了许多,异步回调函数的控制不如同步方式那样直观。但有一点我想应该是要注意的,就是回调函数应该轻装上阵,不应该处理过多的事务,对传递数据的处理,应该交给其它线程进行处理。 4.IOCP(完成端口)大概性能:约20000~50000个客户端连接 实现:现在.NET下有一些伪IOCP,大家可以去搜索一下,还没有见过开放出来的用这些伪IOCP来实现的SOCKET例子。我说的20000~50000个客户端连接,是指在C++下开发的情况,这样的情况下,需要用到的基本技术还包括内存池、查询算法等。伪IOCP能实现多少最大连接,没有资料可以查,如果有朋友知道,可以讨论一下。另外上 面提到的许多数据,是从一些资料上摘抄下来的,我没有自己试过,仅仅是拿出来和大家讨论一下。1. Introduction - Native Win32 IOCPI/O Completion Ports (IOCP) supported on Microsoft Windows platforms has two facets. It first allows I/O handles like file handles, socket handles, etc., to be associated with a completion port. Any async I/O completion event related to the I/O handle associated with the IOCP will get queued onto this completion port. This allows threads to wait on the IOCP for any completion events. The second facet is that we can create a I/O completion port that is not associated with any I/O handle. In this case, the IOCP is purely used as a mechanism for efficiently providing a thread-safe waitable queue technique. This technique is interesting and efficient. Using this technique, a pool of a few threads can achieve good scalability and performance for an application. Here is a small example. For instance, if you are implementing a HTTP server application, then you need to do the following mundane tasks apart from the protocol implementation:Create a client connection listen socket. Once we get the client connection, use the client socket to communicate with the client to and fro. You can implement it by creating one dedicated thread per client connection that can continuously communicate with the client to and fro. But this technique quickly becomes a tremendous overhead on the system, and will reduce the performance of the system as the number of simultaneous active client connections increase. This is because, threads are costly resources, and thread switching is the major performance bottle neck especially when there are more number of threads.The best way to solve this is to use an IOCP with a pool of threads that can work with multiple client connections simultaneously. This can be achieved using some simple steps...Create a client connection listen socket. Once we get the client connection, post an IOCP read message on the socket to an IOCP. One of the threads waiting for completion events on this IOCP will receive the first read message for the client. It immediately posts another read onto the same IOCP and continues processing the read message it got. Once processing the read message is completed, it again waits on the IOCP for another event. This technique will allow a small pool of threads to efficiently handle communication with hundreds of client connections simultaneously. Moreover, this is a proven technique for developing scalable server side applications on Windows platforms.The above is a simplified description of using IOCP in multithreaded systems. There are some good in-depth articles on this topic in CodeProject and the Internet. Do a bit of Googling on words like IO Completion Ports, IOCP, etc., and you will be able to find good articles.2. Introduction - Managed IOCPManaged IOCP is a small .NET class library that provides the second facet of Native Win32 IOCP. This class library can be used both by C# and VB.NET applications. I chose the name Managed IOCP to keep the readers more close to the techniques they are used to with native Win32 IOCP. As the name highlights, Managed IOCP is implemented using pure .NET managed classes and pure .NET synchronization primitives. At its core, it provides a thread-safe object queuing and waitable object receive mechanism. Apart from that, it provides a lot more features. Here is what it does:Multiple Managed IOCP instances per process. Registration of multiple threads per Managed IOCP instance. Dispatching System.Object types to a threadsafe queue maintained by each Managed IOCP instance. Waitable multi-thread safe retrieval of objects from the Managed IOCP instance queue by all the threads registered for that particular Managed IOCP instance. Ability to restrict the number of concurrent active threads processing the queued objects related to a particular Managed IOCP instance. Policy based replaceable/customizable approach for choosing a registered thread to process the next available queued object. Ability to pause the Managed IOCP processing. Internally, pauses processing of queued objects by registered threads. Also, by default, disallows enqueuing new objects (can be changed). Run the Managed IOCP instance. Internally re-starts the processing of queued objects by registered threads. Also allows enqueuing new objects (if it is disallowed previously). Modify the max. allowed concurrent threads at runtime. Provides easy accessibility to Managed IOCP instance runtime properties like... Number of active concurrent threads. Number of objects left in queue. Number of allowed concurrent threads. Running status. Safe and controlled closing of a Managed IOCP instance. 2.1. Managed IOCP in Job/Task Oriented Business ProcessesManaged IOCP can be used in other scenarios apart from the sample that I mentioned in the introduction to native Win32 IOCP. It can be used in process oriented server side business applications. For instance, if you have a business process ( _not_ a Win32 process) with a sequence of tasks that will be executed by several clients, you will have to execute several instances of the business process, one for each client in parallel. As mentioned in my introduction to native Win32 IOCP, you can achieve this by spawning one dedicated thread per business process instance. But the system will quickly run out of resources, and the system/application performance will come down as more instances are created. Using Managed IOCP, you can achieve the same sequential execution of multiple business process instances, but with fewer threads. This can be done by dispatching each task in a business process instance as an object to Managed IOCP. It will be picked up by one of the waiting threads and will be executed. After completing the execution, the thread will dispatch the next task in the business process instance to the same Managed IOCP, which will be picked up by another waiting thread. This is a continuous cycle. The advantage is that you will be able to achieve the sequential execution goal of a business process, as only one waiting thread can receive a dispatched object, and at the same time keep the system resource utilization to required levels. Also, the system and business process execution performance will increase as there are few threads executing multiple parallel business processes.3. Using Managed IOCP in .NET applicationsMultithreaded systems are complex in the context that most problems will show up in real time production scenarios. To limit the possibility of such surprises while using Managed IOCP, I created a test application using which several aspects of the Managed IOCP library can be tested. Nevertheless, I look forward for any suggestions/corrections/inputs to improve this library and its demo application.Before getting into the demo application, below is the sequence of steps that an application would typically perform while using the Managed IOCP library:Create an instance of the ManagedIOCP class: 2. using Sonic.Net;ManagedIOCP mIOCP = new ManagedIOCP();The ManagedIOCP constructor takes one argument, concurrentThreads. This is an integer that specifies how many maximum concurrent active threads are allowed to process objects queued onto this instance of ManagedIOCP. I used a no argument constructor, which defaults to a maximum of one concurrent active thread.From a thread that needs to wait on objects queued onto the ManagedIOCP instance, call the Register() method on the ManagedIOCP instance. This will return an instance of the IOCPHandle class. This is like native Win32 IOCP handle, using which the registered thread can wait on the arrival of objects onto the ManagedIOCP instance. This thread can use the Wait() method on the IOCPHandle object. The Wait() will indefinitely wait until it grabs an object queued onto the ManagedIOCP instance to which the calling thread is registered. It either comes out with an object, or an exception in case the ManagedIOCP instance is stopped (we will cover this later). 4. IOCPHandle hIOCP = mIOCP.Register();5. while(true)6. {7. try8. {9. object obj = hIOCP.Wait();10. // Process the object11. 12. }13. catch(ManagedIOCPException e)14. {15. break;16. }17. catch(Exception e)18. {19. break;20. }}Any thread (one that is registered with the ManagedIOCP instance and any non-registered thread) that has access to the ManagedIOCP instance can dispatch (Enqueue) objects to it. These objects are picked up by waiting threads that are registered with the ManagedIOCP instance onto which objects are being dispatched. 22. string str = "Test string";mIOCP.Dispatch(str);When a thread decides not to wait for objects any more, it should un-register with the ManagedIOCP instance. mIOCP.UnRegister();Once the application is done with an instance of ManagedIOCP, it should call the Close() method on it. This will release any threads waiting on this instance of ManagedIOCP, clears internal resources, and resets the internal data members, thus providing a controlled and safe closure of a ManagedIOCP instance. mIOCP.Close();There are certain useful statistics that are exposed as properties in the ManagedIOCP class. You can use them for fine tuning the application during runtime.// Current number of threads that are // concurrently processing the objects queued // onto this instance of Managed IOCP // (This is readonly property) int activeThreads = mIOCP.ActiveThreads;// Max number of concurrent threads // allowed to process objects queued onto this // instance of Managed IOCP (This is a read/write property) int concurThreads = mIOCP.ConcurrentThreads;// Current count of objects queued onto this Managed IOCP instance. // NOTE: This value may change very quickly // as multiple concurrent threads might // be processing objects from this instance of Managed IOCP queue. // So _do not_ depend on this value // for logical operations. Use this only for // monitoring purpose (Status reporting, etc.) // and during cleanup processes // (like not exiting main thread untill the queued object becomes 0, // i.e. no more objects to be processed, etc) // (This is readonly property) int qCount = mIOCP.QueuedObjectCount;// Number of threads that are registered with this instance of Managed IOCP // (This is readonly property) int regThreadCount = mIOCP.RegisteredThreads;3.1. Advanced usageFollowing are the advanced features of Managed IOCP that need to be used carefully.Managed IOCP execution can be paused at runtime. When a Managed IOCP instance is paused, all the threads registered with this instance of Managed IOCP will stop processing the queued objects. Also, if the 'EnqueueOnPause' property of the ManagedIOCP instance is false (by default, it is false), then no thread will be able to dispatch new objects onto the Managed IOCP instance queue. Calling Dispatch on the ManagedIOCP instance will throw an exception in the Pause state. If the 'EnqueueOnPause' property is set to true, then threads can dispatch objects onto the queue, but you need to be careful while setting this property to true, as this will increase the number of pending objects in the queue, thus occupying more memory. Also, when the Managed IOCP instance is re-started, all the registered threads will suddenly start processing a huge number of objects thus creating greater hikes in the system resource utilization.mIOCP.Pause();Once paused, the ManagedIOCP instance can be re-started using the Run method.mIOCP.Run();The running status of the Managed IOCP instance can be obtained using the IsRunning property:bool bIsRunning = mIOCP.IsRunning;You can retrieve the System.Threading.Thread object of the thread associated with the IOCPHandle instance, from its property named 'OwningThread'.3.2. Demo ApplicationI provided two demo applications with similar logic. The first is implemented using Managed IOCP, the other using native Win32 IOCP. These two demo applications perform the following steps:Create a global static ManagedIOCP instance or native Win32 IOCP. Create five threads. Each thread will dispatch one integer value at a time to the ManagedIOCP instance or native Win32 IOCP until the specified number of objects are completed. Start (creates a new set of five threads) and stop (closes the running threads) the object processing. The Sonic.Net (ManagedIOCP) demo application additionally demonstrates the following features of Managed IOCP that are unavailable in the Win32 IOCP:Pause and continue object processing during runtime. Change concurrent threads at runtime. Statistics like, Active Threads, Maximum Concurrent threads, Queued Objects Count and Running Status of Managed IOCP. Below is the image showing both the demo applications after their first cycle of object processing:Demo application resultsAs you can see in the above figure, Managed IOCP gives the same speed (slightly even better) as native Win32 IOCP. The goal of these two demo applications is _not_ to compare the speed or features of Win32 IOCP with that of Managed IOCP, but rather to highlight that Managed IOCP provides all the advantages of native Win32 IOCP (with additional features) but in a purely managed environment.I tested these two demo applications on a single processor CPU and a dual processor CPU. The results are almost similar, in the sense the Managed IOCP is performing as good as (sometimes performing better than) native Win32 IOCP.3.3. Source and demo application filesBelow are the details of the files included in the article's Zip file:Sonic.Net (folder) - I named this class library as Sonic.Net (Sonic stands for speed). The namespace is also specified as Sonic.Net. All the classes that I described in this article are defined within this namespace. The folder hierarchy is described below: 2. Sonic.Net3. |4. --> Assemblies5. |6. --> Solution Files7. |8. --> Sonic.Net9. |10. --> Sonic.Net Console Demo 11. |--> Sonic.Net Demo ApplicationThe Assemblies folder contains the Sonic.Net.dll (contains the ObjectPool, Queue, ManagedIOCP, IOCPHandle, and ThreadPool classes), Sonic.Net Demo Application.exe (demo application showing the usage of ManagedIOCP and IOCPHandle classes), and Sonic.Net Console Demo.exe (console demo application showing the usage of ThreadPool and ObjectPool classes).The Solution Files folder contains the VS.NET 2003 solution file for the Sonic.Net assembly project, Sonic.Net demo application WinForms project, and Sonic.Net console demo project.The Sonic.Net folder contains the Sonic.Net assembly source code.The Sonic.Net Console Demo folder contains the Sonic.Net console demo application source code. This demo shows the usage of the Managed IOCP ThreadPool, which is explained in my Managed I/O Completion Ports - Part 2 article. This demo uses a file that will be read by the ThreadPool threads. Please change the file path to a valid one on your system. The code below shows the portion in the code to change. This code is in the ManagedIOCPConsoleDemo.cs file.public static void ReadData(){ StreamReader sr = File.OpenText(@"C:\aditya\downloads\lgslides.pdf"); string st = sr.ReadToEnd(); st = null; sr.Close(); Thread.Sleep(100);}The Sonic.Net Demo Application folder contains the Sonic.Net demo application source code.Win32IOCPDemo (folder) - This folder contains the WinForms based demo application for demonstrating Win32 IOCP usage using PInvoke. When compiled, the Win32IOCPDemo.exe will be created in the Win32IOCPDemo\bin\debug or Win32IOCPDemo\bin\Release folder based on the current build configuration you selected. The default build configuration is set to Release mode. 4. Inside Managed IOCPThis section discusses the how and why part of the core logic that is used to implement Managed IOCP.4.1. Waiting and retrieving objects in Managed IOCPManaged IOCP provides a thread safe object dispatch and retrieval mechanism. This could have been achieved by a simple synchronized queue. But with synchronized queue, when a thread (thread-A) dispatches (enqueues) an object onto the queue, for another thread (thread-B) to retrieve that object, it has to continuously monitor the queue. This technique is inefficient as thread-B will be continuously monitoring the queue for arrival of objects, irrespective of whether the objects are present in the queue. This leads to heavy CPU utilization and thread switching in the application when multiple threads are monitoring the same queue, thus degrading the performance of the system.Managed IOCP deals with this situation by attaching an auto reset event to each thread that wants to monitor the queue for objects and retrieve them. This is why any thread that wants to wait on a Managed IOCP queue and retrieve objects from it has to register with the Managed IOCP instance using its 'Register' method. The registered threads wait for the object arrival and retrieve them using the 'Wait' method of the IOCPHandle instance. The IOCPHandle instance contains an AutResetEvent that will be set by the Managed IOCP instance when any thread dispatches an object onto its queue. There is an interesting problem in this technique. Let us say that there are three threads, thread-A dispatching the objects, and thread-B and thread-C waiting on object arrival and retrieving them. Now, say if thread-A dispatches 10 objects in its slice of CPU time. Managed IOCP will set the AutoResetEvent of thread-B and thread-C, thus informing them of the new object arrival. Since it is an event, it does not have an indication of how many times it has been set. So if thread-B and thread-C just wake up on the event set and retrieve one object each from the queue and again waits on the event, there would be 8 more objects left over in the queue unattended. Also, this mechanism would waste the CPU slice given to thread-B and thread-C as they are trying to go into waiting mode after processing a single object from the Managed IOCP queue.So in Managed IOCP, when thread-B and thread-C call the 'Wait' method on their respective IOCPHandle instances, the method first tries to retrieve an object from the Managed IOCP instance queue before waiting on its event. If it was able to successfully retrieve the object, it does。

如果在Eclipse运行Hadoop的mapreduce。需要把Hadoop路劲下的 etc/hadoop下面的你配置好的配置文件hdfs-site.xml拷贝到你Eclipse项目的跟目录下。

原文地址:http://www.qianchusai.com/CompletionException-100.html

ques,缺少维生素b的表现

ques,缺少维生素b的表现

9脚电平显示电路,tl494cn9脚10脚没有输出电压

9脚电平显示电路,tl494cn9脚10脚没有输出电压

对位组件英文翻译,对位英文怎么写

对位组件英文翻译,对位英文怎么写

焦作一日游必去的地方,焦作一日游必去的地方有哪些

焦作一日游必去的地方,焦作一日游必去的地方有哪些

英语超短小故事5句,英语15~20字小短文带翻译

英语超短小故事5句,英语15~20字小短文带翻译

kipper,kipper and the giant牛津树

kipper,kipper and the giant牛津树

gif出处-70

gif出处-70

酷听听书,酷听听书app下载官网

酷听听书,酷听听书app下载官网

Consular-90

Consular-90

dental,dental怎么读

dental,dental怎么读