我希望能够执行嵌套的shell命令.例如;
final String cmd = 'for i in pom.xml projects.xml; do find . -name $i | while read fname; do echo $fname; done;done'
Run Code Online (Sandbox Code Playgroud)
我尝试了以下语法,但无法让它运行.
def result = cmd.execute();def result = ['sh', '-c', cmd].execute();def result = ('sh -c for i in pom.xml projects.xml; do find . -name $i | while read fname; do echo $fname; done;done').execute()我很感激这里的帮助.
如何使用我if在if块外的语句中声明的变量?
if(z<100){
int amount=sc.nextInt();
}
while(amount!=100)
{ //this is wrong.it says we cant find amount variable ?
something
}
Run Code Online (Sandbox Code Playgroud) 这是我的xml代码......
<flow>
<TaskID>100</TaskID>
<TaskID>101</TaskID>
<TaskID>102</TaskID>
<TaskID>103</TaskID>
</flow>
Run Code Online (Sandbox Code Playgroud)
我想知道如何在java中的for循环中获取taskID值.请帮我...
我正在编写如下代码:
String s1=new String("hi");
System.out.println(s1.hashCode());
String s2=new String("hi");
System.out.println(s2.hashCode());
String s3=s1.intern();
String s4=s2.intern();
System.out.println(s3.hashCode());
System.out.println(s4.hashCode());
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,所有变量都打印相同的哈希码:
3329
3329
3329
3329
Run Code Online (Sandbox Code Playgroud)
这是上述代码的正确输出吗?
在Java中,我想做这样的事情:
Object r = map.get(t);
if (r == null) {
r = create(); // creating r is an expensive operation.
map.put(t, r);
}
Run Code Online (Sandbox Code Playgroud)
现在,代码片段可以在多线程环境中执行.
map可以是ConcurrentHashMap.
但是我如何使逻辑成为原子?
请不要像"同步"块那样给我一些简单的解决方案.我希望这个问题可以一劳永逸地解决.
这是代码:
public static File backupDB() throws IOException {
File file = null;
file = new File("BKUP_DB_"
+ Calendar.getInstance()).replace("/", "-") + ".sql");
String executeCmd = "mysqldump -u " + "dbUserName" + " -p" + "dbPassword"
+ " " + "dbName" + " > " +file.getPath();
Process runtimeProcess;
try {
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
System.out.println("Backup created successfully");
runtimeProcess.destroy();
return file;
} else {
System.out.println("Could not create the backup");
}
} catch (Exception ex) { …Run Code Online (Sandbox Code Playgroud) 我正在阅读ArrayList 类的源代码,我想知道方法add(E e, Object[] elementData, int s)。
我已经阅读了它的描述,但我不明白其中的某些部分。
像这些:
将方法字节码大小保持在 35(-XX:MaxInlineSize 默认值)以下,这有助于在 C1 编译循环中调用 add(E) 时。
哪一个更优或者有什么不同?
String s = methodThatReturnsString();
int i = methodThatReturnsInt();
thirdMethod(s, i);
Run Code Online (Sandbox Code Playgroud)
要么
thirdMethod(methodThatReturnsString(), methodThatReturnsInt());
Run Code Online (Sandbox Code Playgroud)
通过最优,我的意思是在内存使用等方面最优.
我保存到会话的对象是a LocalizationContext,它不可序列化,我的Tomcat是5.5.28,而qa服务器是Tomcat 5.5.30.这是来自Tomcat文档:
每当Catalina正常关闭并重新启动,或者触发应用程序重新加载时,标准的Manager实现将尝试将所有当前活动的会话序列化为通过pathname属性定位的磁盘文件.然后,当应用程序重新加载完成时,所有这些保存的会话将被反序列化并激活(假设它们在平均时间内没有过期).
为了成功恢复会话属性的状态,所有这些属性必须实现java.io.Serializable接口.您可以通过
<distributable>在Web应用程序部署描述符(/WEB-INF/web.xml)中包含该元素,使Manager强制实施此限制 .
这让我觉得它应该打破我的本地,并且你永远不能在Tomcat中保存会话属性,除非它实现Serializable.
编辑:
对不起,为了更清楚,我的问题是双重的.是否所有会话属性都必须是可序列化的,如果这样做,为什么它仍然可以在我的本地环境中工作?
我正在尝试运行从Sun Java站点获取的代码(我没有复制它,查看它并编写它,因为它可以帮助我记住代码).
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class CharEx{
FileReader inputStream = null;
FileWriter outputStream = null;
public static void main(String args[]) throws IOException{
FileReader inputStream = null;
FileWriter outputStream = null;
try{
inputStream = FileReader("xanadu.txt");
outputStream = FileWriter("out.txt");
int c;
while ((c = inputStream.read()) != -1){
outputStream(c);
}
}
finally{
if(inputStream !=null){
inputStream.close();
}
if(outputStream !=null){
outputStream.close();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是我遇到了错误.
D:\Java>javac CharEx.java
CharEx.java:14: cannot find symbol
symbol : method FileReader(java.lang.String)
location: class CharEx
inputStream = …Run Code Online (Sandbox Code Playgroud) java ×9
arraylist ×1
filereader ×1
filewriter ×1
groovy ×1
hashcode ×1
httpsession ×1
io ×1
linux ×1
mysql ×1
optimization ×1
runtime.exec ×1
session ×1
shell ×1
string ×1
tomcat ×1
xml ×1