我手边有一个问题,我没有得到使用哪种设计模式.问题是这样的:
我必须构建一个具有'N'状态的系统,并且我的系统必须根据某些条件从任何状态转换到任何其他状态.例如:在条件1下,从状态1移动到3,在条件2上从状态1移动到4.
甚至从一个状态到另一个状态的转换也可以在两个或更多个不同的条件下完成.
例如,从状态1到状态3的转换可以在以下
情况下完成:条件1:"它是星期日"
条件2:"它的下雨"
条件3:"它的下雨和星期日"
在每种情况下,状态3的处理可以是不同.
我希望我能够清楚地理解这个问题.请帮助.
非常感谢
我在Tomcat中运行Java Web应用程序.该应用程序使用Quartz框架定期调度cron作业.这个cron工作涉及解析4+ MB xml文件,我正在使用JDOM API.xml文件包含大约3600个要解析的节点,因此要在DB中更新数据,我按顺序执行此操作.
在解析了几乎一半的文件后,我的应用程序抛出了Out of Memory Exception.堆栈跟踪是:
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3210)
at java.lang.String.<init>(String.java:216)
at java.lang.StringBuffer.toString(StringBuffer.java:585)
at org.netbeans.lib.profiler.server.ProfilerRuntimeMemory.traceVMObjectAlloc(ProfilerRuntimeMemory.java:170)
at java.lang.Throwable.getStackTraceElement(Native Method)
at java.lang.Throwable.getOurStackTrace(Throwable.java:590)
at java.lang.Throwable.getStackTrace(Throwable.java:582)
at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:155)
at org.apache.juli.logging.DirectJDKLog.error(DirectJDKLog.java:135)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1603)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:619)
Exception in thread "*** JFluid Monitor thread ***" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.Vector.ensureCapacityHelper(Vector.java:226)
at java.util.Vector.add(Vector.java:728)
at org.netbeans.lib.profiler.server.Monitors$SurvGenAndThreadsMonitor.updateSurvGenData(Monitors.java:230)
at org.netbeans.lib.profiler.server.Monitors$SurvGenAndThreadsMonitor.run(Monitors.java:169)
Nov 30, 2009 2:22:05 PM org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor processChildren
SEVERE: Exception invoking periodic operation: …Run Code Online (Sandbox Code Playgroud) 我有一个模式,@@{}并给出一个字符串,我需要找出大括号之间的所有字符串.
示例:如果我的字符串是 Hi This is @@{first} and second is @@{second} along with third @@{third} string
我期望的输出是一个由元素组成的字符串数组:
first
second
third
Run Code Online (Sandbox Code Playgroud)
我的Java代码如下:
Pattern p = Pattern.compile("\\@\\@\\{(.+?)\\}");
Matcher match = p.matcher("Hi This is @@{first} and second is @@{second} along" +
"with third @@{third} string");
while(match.find()) {
System.out.println(match.group());
}
Run Code Online (Sandbox Code Playgroud)
但我得到的输出是
@@{first}
@@{second}
@@{third}
Run Code Online (Sandbox Code Playgroud)
请指导我如何获得所需的输出以及我正在做的错误
我有一个包含多行的输入字符串(由\n划分).我需要在行中搜索一个模式,如果找到它,则用空字符串替换整行.
我的代码看起来像这样,
Pattern p = Pattern.compile("^.*@@.*$");
String regex = "This is the first line \n" +
"And this is second line\n" +
"Thus is @@{xyz} should not appear \n" +
"This is 3rd line and should come\n" +
"This will not appear @@{abc}\n" +
"But this will appear\n";
Matcher m = p.matcher(regex);
System.out.println("Output: "+m.group());
Run Code Online (Sandbox Code Playgroud)
我希望回复如下:
Output: This is the first line
And this is second line
This is 3rd line and should come
But this will appear.
Run Code Online (Sandbox Code Playgroud)
我无法得到它,请帮帮我.
谢谢,
阿米特