小编Pom*_*rio的帖子

如何设置一个非常大的JVM堆大小?

根据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?

jvm

7
推荐指数
2
解决办法
3万
查看次数

如何在控制器中使用JAXB和Spring @ResponseBody生成正确的站点地图命名空间?

除了我无法正确创建命名空间之外,一切正常.任何帮助深表感谢!

我的控制器:

@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)

我期望产生什么: …

sitemap spring controller jaxb

6
推荐指数
1
解决办法
2197
查看次数

如果不使用Xmx会发生什么?

根据JVM的文档,如果使用太大的Xms参数,JVM将无法启动.所以,我问,如果我不使用会发生什么?我的VM是否可以无限期增长?它只会在物理内存耗尽时停止吗?

jvm

6
推荐指数
2
解决办法
3517
查看次数

在Grails视图中使用HTML编解码器时保留新行

Grails XSS预防功能非常方便,所以我使用它启用它:

grails.views.default.codec = "html"
Run Code Online (Sandbox Code Playgroud)

但是,这会产生html的问题textareas.如果我们完成textarea并使用Enter来断行,则新行将保存在数据库中,但在视图中会被忽略.我可以使用<%=%>replaceAll('\n',"<br>")修复换行符,但填写的HTML代码textarea不会被转义,也不会有XSS预防!

你会如何解决这个问题?

xss grails

5
推荐指数
1
解决办法
4153
查看次数

如何使用Spring将SessionFactory连接到Hibernate Interceptor?

所以,我按照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?

spring hibernate sessionfactory interceptor

5
推荐指数
0
解决办法
5458
查看次数

证明SimpleDateFormat不是线程安全的

我想向同事展示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)

java multithreading

4
推荐指数
1
解决办法
1343
查看次数

@ExceptionHandler未被调用

经过一段时间研究和尝试不同的东西后,我仍然无法在我的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)

spring exception-handling

3
推荐指数
1
解决办法
2279
查看次数

为什么Mockito给我默认的模拟对象?

在我断言的下面的琐碎练习中,我期待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)

}

mockito

2
推荐指数
1
解决办法
559
查看次数

为什么Spring不会在RuntimeException上回滚?

我正在尝试编写一段代码,在其中我可以看到在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 transactions

2
推荐指数
1
解决办法
2436
查看次数

Spring @Controller生命周期

我是Spring MVC的新手,想知道它如何处理请求,更具体地说:

  1. 我想知道Spring @ Controller的生命周期与Servlet的生命周期有什么关系?
  2. 我还想更好地了解多线程环境的最佳实践(例如,在Servlet中,当对象从池中重用时,多个HTTP请求可见的类属性)?

model-view-controller spring multithreading controller spring-mvc

1
推荐指数
1
解决办法
1782
查看次数

字符串池的意外行为

我有以下测试:

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会分配一个和两个指向池中相同的字符串.在这种情况下,为什么我的理解错了?

java string-comparison

1
推荐指数
1
解决办法
118
查看次数