草庐IT

CLOSE_SYSTEM_DIALOGS

全部标签

java - java.sql.Connection.close() 对 java.sql.Statement 对象等的影响

关闭java.sql.Connection是否也会关闭从该连接获得的所有语句、准备语句等?或者,如果我关闭连接但未关闭语句等,是否会发生内存泄漏? 最佳答案 Doesclosingajava.sql.Connectionalsocloseallthestatements,preparedstatements,etc.obtainedfromthatconnection?OristheregoingtobememoryleakifIclosetheconnectionbutleavethestatements,etc.unclosed

java - Java 的 System.out.print() 会一直缓冲到 println() 吗?

我今天无意中听到关于System.out.print()的争论。一个人声称,由于print()不包括终止\n,它写入的缓冲区最终将填满并开始丢失数据。另一个人声称他们一直在为他们所有的Java程序使用System.out.print()并且从未遇到过这个问题。第一人称对吗?如果stdout已满,System.out.print()是否可以开始阻止或丢弃数据?是否有导致此问题的代码示例? 最佳答案 当System.out.print使用的缓冲区填满时,输出将写入文件(或连接到程序标准输出流的终端或其他数据目标),导致一个空缓冲区。在不

java - System.getProperty ("java.class.path") 和 getClassLoader.getURLs() 有什么区别?

System.getProperty("java.class.path")返回我程序的类路径。然而getClassLoader().getURLs()也为我提供了类路径(参见我的另一篇文章:howtousegetClassLoader)这两种方式有什么区别? 最佳答案 主要区别在于它们返回的内容:getClassLoader.getURLs()返回用于加载类和资源的URL的搜索路径。这包括指定给构造函数的原始URL列表,以及随后由addURL()方法附加的任何URL,请参阅linkSystem.getProperty("java.c

java - 使用 System.out.print 与 println 的多线程问题

我有以下线程,它每200毫秒打印一个点:publicclassProgress{privatestaticbooleanthreadCanRun=true;privatestaticThreadprogressThread=newThread(newRunnable(){publicvoidrun(){while(threadCanRun){System.out.print('.');System.out.flush();try{progressThread.sleep(200);}catch(InterruptedExceptionex){}}}});publicstaticvoid

java - 奇怪的 'out' 变量,System.out.println()

以下是java.lang.System类(JDK1.6版本)的代码publicfinalstaticPrintStreamout=nullPrintStream();//outissetto'null'privatestaticPrintStreamnullPrintStream()throwsNullPointerException{if(currentTimeMillis()>0){returnnull;}thrownewNullPointerException();}当我们在代码中编写System.out.println("Something");时,为什么即使'out'设置为'

java - 为什么 java 的 inputstream.close() 会阻塞?

我的Java程序使用ProcessBuilder(将redirectErrorStream设置为true)并有一个循环来运行进程的输入流的读取方法,这是阻塞的。然后我调用的外部程序停止等待输入和标准输入。我现在想杀死这个过程。这不是通过(在单独的线程中)调用进程的destroy方法,并调用inputstream的close方法来停止read方法阻塞来完成的,这样我的初始线程就可以结束它的生命了吗?由于某些原因process.getInputStream().close()block。从JavaDoc我不明白为什么会发生这种情况。此外,我不明白为什么javadoc说“InputStrea

java - 为什么 System.out.print() 不工作?

所以我正忙着编写一个我认为是相对简单的“读取文件”程序。我遇到了很多编译错误,所以我开始尝试一次编译一行,看看我在哪里被清理了。这是我到目前为止的位置:importjava.nio.file.*;importjava.io.*;importjava.nio.file.attribute.*;importjava.nio.channels.FileChannel;importjava.nio.ByteBuffer;importstaticjava.nio.file.StandardOpenOption.*;importjava.util.Scanner;importjava.text.*

java - Java线程中的System.exit

我的主线程创建了一个新线程当新线程调用System.exit(-1)时,我的主线程被关闭。如何处理退出代码并保持主线程Activity?附言。新线程会调用其他.jar文件中的一些方法,所以我不能修改它。 最佳答案 你不能。终止当前运行的Java虚拟机。该参数用作状态代码;按照惯例,非零状态代码表示异常终止。那是javadoc。因此该方法将终止整个JVM。不仅仅是线程.... 关于java-Java线程中的System.exit,我们在StackOverflow上找到一个类似的问题:

java - System.currentTimeMillis() 方法真的返回当前时间吗?

基于link中提出的想法我实现了几种不同的“sleep方法”。其中一种方法是“二进制sleep”,它看起来像这样:while(System.currentTimeMillis()因为检查是否已经到达下一个时间步长发生在开始时,我预计该方法运行时间太长。但是模拟误差的累积分布(预期时间-实时)如下所示:alttexthttp://img267.imageshack.us/img267/4224/errorvscummulativearran.jpg有人知道我为什么会得到这个结果吗?也许System.currentTimeMillis()方法并没有真正返回当前时间?BR,马库斯@irrep

java - PreparedStatement 的 "close"与 Connection 的关系?

Javadoc说PreparedStatement的.close()说它..ReleasesthisStatementobject'sdatabaseandJDBCresourcesimmediatelyinsteadofwaitingforthistohappenwhenitisautomaticallyclosed.Itisgenerallygoodpracticetoreleaseresourcesassoonasyouarefinishedwiththemtoavoidtyingupdatabaseresources.CallingthemethodcloseonaStatem