我有一个使用数据源的Tomcat 8项目(见下文)
<Resource auth="Container"
name="jdbc/JtmDS"
driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
type="javax.sql.DataSource"
username="xfer"
password="xfer10"
url="jdbc:derby:/home/PUID/tm/control/JtmDB"
initialSize="25"
maxTotal="100"
maxIdle="30"
maxWaitMillis="10000"
removeAbandonedOnBorrow="true"
removeAbandonedTimeout="20" />
Run Code Online (Sandbox Code Playgroud)
这非常有效.
但是url是一个硬编码的路径 /home/PUID/tm/control/JtmDB
当它投入生产时,路径的PUID部分将在众多系统中不同.我有一个环境变量集export PUID=abcd
应用程序的其余部分可以使用类似System.getenv( )或${env:PUID}适当的东西.
一切都很好.
我的问题很简单:如何在context.xml中创建一个可以从环境变量中读取的变量?
我有一个执行几个不同任务的线程.每项任务都取决于前一项任务是否成功.
如果这是我可能写的方法(长手):
public boolean outerMethod()
{
boolean success= performTask();
if(success == false)
{
return false;
}
// more processing here if success == true
}
Run Code Online (Sandbox Code Playgroud)
然后从outerMethod后面走到呼叫者处,不再进行进一步的处理
但...
如果我是run()一个线程的方法,我做了如下所示的事情......
我怎么能在那里结束当前的线程呢?
public void run()
{
boolean success = performTask();
if( success == false )
{
/* here is where I want to exit this thread */
}
// further processing if success == true
}
Run Code Online (Sandbox Code Playgroud)