根据JVM 6文档,服务器类机器默认接收初始堆大小为1/4 RAM或1GB.考虑到我们的Solaris 64Bit服务器具有64 GB,初始堆大小默认为256 MB.因此,我需要使用4GB的XMX参数手动设置堆大小.但是,当我添加"-Xmx4096M"时,Tomcat无法启动.这是错误消息:
Invalid maximum heap size: -Xmx4096M
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
Run Code Online (Sandbox Code Playgroud)
什么应该是我的命令行参数,以允许我的堆增长到4GB?
除了我无法正确创建命名空间之外,一切正常.任何帮助深表感谢!
我的控制器:
@Controller
@RequestMapping("/sitemap")
public class SitemapController
{
public @ResponseBody XMLURLSet getSitemap(){
XMLURLSet urlSet = new XMLURLSet();
//populate urlList
urlSet.setUrl(urlList);
return urlSet;
}
}
Run Code Online (Sandbox Code Playgroud)
我的urlset:
@XmlRootElement(name = "url")
public class XMLURL {
String loc;
@XmlElement(name = "loc")
public String getLoc(){
return loc;
}
public void setLoc(String loc){
this.loc = loc;
}
Run Code Online (Sandbox Code Playgroud)
}
我的网址元素:
@XmlRootElement(name = "urlset", namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")
public class XMLURLSet{
List<XMLURL> url;
public List<XMLURL> getUrl(){
return url;
}
public void setUrl(List<XMLURL> url){
this.url = url;
}
}
Run Code Online (Sandbox Code Playgroud)
我期望产生什么: …
根据JVM的文档,如果使用太大的Xms参数,JVM将无法启动.所以,我问,如果我不使用会发生什么?我的VM是否可以无限期增长?它只会在物理内存耗尽时停止吗?
Grails XSS预防功能非常方便,所以我使用它启用它:
grails.views.default.codec = "html"
Run Code Online (Sandbox Code Playgroud)
但是,这会产生html的问题textareas.如果我们完成textarea并使用Enter来断行,则新行将保存在数据库中,但在视图中会被忽略.我可以使用<%=%>和replaceAll('\n',"<br>")修复换行符,但填写的HTML代码textarea不会被转义,也不会有XSS预防!
你会如何解决这个问题?
所以,我按照Hibernate文档来配置拦截器(链接).然后,我在AnnotationSessionFactoryBean中注册我的拦截器,如下所示:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="entityInterceptor">
<bean class="domain.interceptor.AddressInterceptor"/>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是在我的拦截器中捕获某些东西时在我的日志表中插入一行.虽然,这引入了循环配置依赖:Interceptor需要SessionFactory而SessionFactory需要Interceptor.我如何在我的拦截器中连接SessionFactory?
我想向同事展示SimpleDateFormat 通过简单的JUnit测试不是线程安全的.下面的类没有说明我的观点(在多线程环境中重用SimpleDateFormat),我不明白为什么.你能发现什么阻止我使用SDF抛出运行时异常吗?
public class SimpleDateFormatThreadTest
{
@Test
public void test_SimpleDateFormat_MultiThreaded() throws ParseException{
Date aDate = (new SimpleDateFormat("dd/MM/yyyy").parse("31/12/1999"));
DataFormatter callable = new DataFormatter(aDate);
ExecutorService executor = Executors.newFixedThreadPool(1000);
Collection<DataFormatter> callables = Collections.nCopies(1000, callable);
try{
List<Future<String>> futures = executor.invokeAll(callables);
for (Future f : futures){
try{
assertEquals("31/12/1999", (String) f.get());
}
catch (ExecutionException e){
e.printStackTrace();
}
}
}
catch (InterruptedException e){
e.printStackTrace();
}
}
}
class DataFormatter implements Callable<String>{
static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date;
DataFormatter(Date date){
this.date = date;
} …Run Code Online (Sandbox Code Playgroud) 经过一段时间研究和尝试不同的东西后,我仍然无法在我的jUnit集成测试中调用我的@ExceptionHandler.请帮帮我理解原因?
@RequestMapping(value = "/someURL", method = RequestMethod.POST)
public ModelAndView batchUpload(@RequestBody final String xml, @RequestParam boolean replaceAll)
throws IOException, URISyntaxException, SAXException, ParserConfigurationException, InvocationTargetException, IllegalAccessException, UnmarshallingFailureException
{
StreamSource source = new StreamSource(new StringReader(xml));
DomainClass xmlDomainClass;
try
{
xmlDomainClass = (DomainClass) castorMarshaller.unmarshal(source);
}
catch (UnmarshallingFailureException me)
{
// some logging. this gets executed
throw me;
}
Run Code Online (Sandbox Code Playgroud)
.
@ExceptionHandler(Throwable.class)
public ModelAndView handleUnmarshallingExceptions(Throwable th)
{
// never executes anything in here
return new ModelAndView( /*some parameters */ );
}
Run Code Online (Sandbox Code Playgroud) 在我断言的下面的琐碎练习中,我期待1,但得到0.为什么我看到这种行为?
public class MockitoTest {
POJO mockedPojo;
@Before
public void setup() {
mockedPojo = mock(POJO.class);
}
@Test
public void testIndifferentMethodInvocationOrder() {
int result1 = mockedPojo.getOne();
assertEquals(1, result1);
}
class POJO {
int count = 1;
int getOne() {
return count++;
}
int getTwo() {
return count++;
}
}
Run Code Online (Sandbox Code Playgroud)
}
我正在尝试编写一段代码,在其中我可以看到在RuntimeException上回滚的@Transaction方法.这应该是预期的默认行为,但它不是我所看到的.有什么想法吗?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:mrpomario/springcore/jdbc/jdbc-testenv-config.xml")
@Transactional // Will rollback test transactions at the end
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class TransactionalTest
{
@Autowired
FeedManagerOne feedManagerOne;
@Test
public void test_RuntimeExceptions_Rollback_Behaviour(){
Feed bogus = new Feed("B", "B", false);
assertFalse(feedManagerOne.exists(bogus));
try {
feedManagerOne.createFeedAndThrowRuntimeException(bogus);
} catch (RuntimeException e) { }
// WRONG! feedManagerOne.exists(bogus) SHOULD return false, but returns true.
assertFalse(feedManagerOne.exists(bogus));
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务:
@Service
public class FeedManagerOne {
@Autowired
JdbcTemplate jdbcTemplate;
@Transactional(readOnly = true)
public boolean exists(Feed feed) {
String query = "SELECT COUNT(*) …Run Code Online (Sandbox Code Playgroud) 我是Spring MVC的新手,想知道它如何处理请求,更具体地说:
model-view-controller spring multithreading controller spring-mvc
我有以下测试:
public class EqualityTest
{
String one = new String("Hello world");
String two = new String("Hello ") + new String("world");
@Test
public void testStringPool()
{
assertFalse(one == two); // FALSE!!!
assertTrue(one.equals(two));
assertTrue(one.intern().equals(two.intern()));
}
}
Run Code Online (Sandbox Code Playgroud)
我原以为由于Java的字符串池特性,VM会分配一个和两个指向池中相同的字符串.在这种情况下,为什么我的理解错了?
spring ×5
controller ×2
java ×2
jvm ×2
grails ×1
hibernate ×1
interceptor ×1
jaxb ×1
mockito ×1
sitemap ×1
spring-mvc ×1
transactions ×1
xss ×1