我有Java主类,在类中,我启动一个新线程,在主,它等待直到线程死亡.在某些时刻,我从线程中抛出一个运行时异常,但是我无法捕获从主类中的线程抛出的异常.
这是代码:
public class Test extends Thread
{
public static void main(String[] args) throws InterruptedException
{
Test t = new Test();
try
{
t.start();
t.join();
}
catch(RuntimeException e)
{
System.out.println("** RuntimeException from main");
}
System.out.println("Main stoped");
}
@Override
public void run()
{
try
{
while(true)
{
System.out.println("** Started");
sleep(2000);
throw new RuntimeException("exception from thread");
}
}
catch (RuntimeException e)
{
System.out.println("** RuntimeException from thread");
throw e;
}
catch (InterruptedException e)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
谁知道为什么?
localhost和真实IP地址有什么区别?
如果我使用http://localhost:8080/index.html和访问应用程序http://192.123.456.001:8080/index.html(例如,192.123.456.001是主机的真实IP地址),有什么区别?
我使用Restlet 框架中的Logger和 FileHandler 在生产模式下记录我的应用程序。但是,我总是收到异常“无法为记录器创建 FileHandler:无法获取 test.log 的锁定”。我该如何解决这个问题?这是代码:
FileHandler aFileHandler = new FileHandler("test.log");
Formatter aFormatter = new SimpleFormatter();
aFileHandler.setFormatter(aFormatter);
aLogger.setLevel(Level.ALL);
aLogger.addHandler(aFileHandler);
Run Code Online (Sandbox Code Playgroud)
该日志文件同时被多个进程使用。
除了.log 文件之外,还创建了许多其他文件,例如“.log.1,.log.2 .....”。有人知道为什么吗?
我正在开发一个GWT Web应用程序,现在我想通过HTTPS保护整个Web应用程序.有人有个主意吗?
我正在使用Jetty Web服务器.
提前致谢!
我有一个关于 Java File 类的问题。例如,当我创建一个 File 实例时,
File aFile = new File(path);
Run Code Online (Sandbox Code Playgroud)
实例 aFile 存储在计算机中的什么位置?或者它存储在JVM中?我的意思是有一个临时文件存储在本地磁盘中吗?
例如,如果我有一个 InputStream 实例,并使用 OutputSteam 将其写入文件
File aFile = new File("test.txt");
OutputStream anOutputStream = new FileOutputStream(aFile);
byte aBuffer[] = new byte[1024];
while( ( iLength = anInputStream.read( aBuffer ) ) > 0)
{
anOutputStream.write( aBuffer, 0, iLength);
}
Run Code Online (Sandbox Code Playgroud)
现在文件 test.txt 存储在哪里?
提前致谢!