我正在尝试评估在我们的应用程序中的一个表中创建的墓碑数量.为此,我试图使用nodetool cfstats.我是这样做的:
create table demo.test(a int, b int, c int, primary key (a));
insert into demo.test(a, b, c) values(1,2,3);
Run Code Online (Sandbox Code Playgroud)
现在我正在制作与上面相同的插页.所以我希望创建3个墓碑.但是在为这个列家族运行cfstats时,我仍然看到没有创建墓碑.
nodetool cfstats demo.test
Average live cells per slice (last five minutes): 0.0
Average tombstones per slice (last five minutes): 0.0
Run Code Online (Sandbox Code Playgroud)
现在我尝试删除记录,但我仍然没有看到任何墓碑被创建.我在这里缺少什么东西?请建议.
BTW其他一些细节,*我们正在使用Java驱动程序的2.1.1版本*我们正在运行Cassandra 2.1.0
我正在尝试使用Spring的Message Source资源包.这是我这样做的方式:
@Component
public class MessageResolver implements MessageSourceAware {
@Autowired
private MessageSource messageSource;
public void setMessageSource(MessageSource messageSource) {
this.messageSource = messageSource;
}
public String getMessage(){
return messageSource.getMessage("user.welcome", new Object[]{"Rama"} , Locale.US);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的文件夹结构:

messages_en_US.properties只包含一行:
user.welcome=Welcome {0}
Run Code Online (Sandbox Code Playgroud)
这是使用的xml配置:
<bean name="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>resourcebundles/messages</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
WARNING: ResourceBundle [resourcebundles/messages] not found for MessageSource: Can't find bundle for base name resourcebundles/messages, locale en_US
Exception in thread "main" org.springframework.context.NoSuchMessageException: No message found under code 'user.welcome' for locale 'en_US'.
Run Code Online (Sandbox Code Playgroud)
但是,如果我将资源包直接移动到资源文件夹下,它工作正常.在这种情况下,这是我正在使用的xml配置:
<bean name="messageSource" …Run Code Online (Sandbox Code Playgroud) 我有一个Hibernate POJO与1.an与一个对象的一对一关联2.与另一个对象的一对多关联(集合)
我正在尝试创建一个Jasper报告,这些关联将转到子报告.对于多对一关联,我传递的数据源如下:
<subreport>
<reportElement x="40" y="16" width="100" height="30"/>
<dataSourceExpression>
<![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{phones})]]>
</dataSourceExpression>
<subreportExpression>
<![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]>
</subreportExpression>
</subreport>
Run Code Online (Sandbox Code Playgroud)
这很好用.这是我为一对一关联定义它的方式
<subreport>
<reportElement x="25" y="91" width="200" height="59"/>
<dataSourceExpression>
<![CDATA[new net.sf.jasperreports.engine.data.JRBeanArrayDataSource([$F{batchHeaderRecord}] as java.lang.Object[])]]>
</dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "batchHeaderReport.jasper"]]>
</subreportExpression>
</subreport>
Run Code Online (Sandbox Code Playgroud)
但是这个没有用.有人可以让我知道我哪里出错吗?
我试图了解 Spring 事务的隔离级别。这是我正在使用的示例:
@Component
public class BookShop {
private Object lockObj = new Object();
@Autowired
private BookDao bookDao;
@Transactional
public void increaseStock(int isbn, int increment){
String threadName = Thread.currentThread().getName();
synchronized (lockObj) {
Book book = bookDao.findByIsbn(isbn);
System.out.println(threadName+" about to increment the stock");
bookDao.updateStock(book, 5);
}
System.out.println(threadName+" has increased the stock ");
sleep(threadName);
System.out.println(threadName+" rolled back stock");
throw new RuntimeException("Stock increased by mistake");
}
@Transactional
public int checkStock(int isbn){
int stock = 0;
String threadName = Thread.currentThread().getName();
synchronized (lockObj) {
System.out.println(threadName+" …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个示例 JMX 应用程序。这是我的 MBean 类:
package com.pramati.jmx;
@Component
@ManagedResource(objectName="modelMBean:type=simple-calculator",
description="Calculator performing basic arithmetic on integers")
public class SimpleCalculator {
private int operand1;
private int operand2;
public SimpleCalculator() {
System.out.println("SimpleCalculator - MBean created!!");
}
@ManagedOperation(description="Addition operation")
public int add() {
return operand1 + operand2;
}
@ManagedOperation(description="Multiplication operation")
public int multiply() {
return operand1 * operand2;
}
@ManagedOperation(description="Division operation")
@ManagedOperationParameters({
@ManagedOperationParameter(name="operand1", description="Dividend"),
@ManagedOperationParameter(name="operand2", description="Divisor")
})
public int divide(int operand1, int operand2) {
if(operand2 == 0) {
throw new IllegalArgumentException("Can not divide by …Run Code Online (Sandbox Code Playgroud) 我使用Jersey2编写了一个示例REST服务.
这是我的web.xml:
<web-app>
<display-name>jerseysample</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.adaequare.rest.config.JerseyResourceInitializer</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
这是我的示例类:
package com.adaequare.resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Hello {
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello(){
return "<html><title>Hello Jersey</title><body><h1>Hello Jersey</h1></body></html>";
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" …Run Code Online (Sandbox Code Playgroud) 我有一个带有嵌套元素和重复标签的 XML。例如:
<person>
<name>Rama</name>
<age>27</age>
<gender>male</gender>
<address>
<doornumber>234</doornumber>
<street>Kanon</street>
<city>Hyderabad</city>
</address>
<qualification>
<degree>M.Sc</degree>
<specialisation>Maths</specialisation>
</qualification>
<qualification>
<degree>B.E.</degree>
<specialisation>Electrical</specialisation>
</qualification>
</person>
Run Code Online (Sandbox Code Playgroud)
现在我想要一个 API 可以将此 XML 转换为 Java 中的地图:
{name="Rama",age="27",gender="male",address={doornumber=234,street="Kanon",city="Hyderabad"},qualification=[{degree="M.Sc",specialisation="Maths"},{degree="B.E.",specialisation="Electrical"}]}
Run Code Online (Sandbox Code Playgroud)
我知道我们可以使用 XStream API 来实现这一点。这里我只是想知道使用 XStream 是否有任何缺点以及是否存在其他更好的 Java API 来实现这一点。有什么建议么?
注意:这应该以通用方式完成,即 Java API 应该适用于任何 XML,而不仅仅是上述 XML。
我正在尝试使用Jersey2构建示例REST服务:
这是我的POM依赖项:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
这是我的web.xml:
<web-app>
<display-name>jerseysample</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.adaequare.rest.config.JerseyResourceInitializer</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
这是我的ResourceConfig实现:
package com.adaequare.rest.config;
import org.glassfish.jersey.server.ResourceConfig;
public class JerseyResourceInitializer extends ResourceConfig {
public JerseyResourceInitializer() {
packages(true, "com.adaequare.resource");
}
}
Run Code Online (Sandbox Code Playgroud)
最后这是我的示例类:
package com.adaequare.resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path; …Run Code Online (Sandbox Code Playgroud) 我使用Jackson fasterxml来解组JSON.在我的对象中有两种属性:输入属性和计算属性.在输入JSON中,我只获得输入值.
计算值实际上取决于输入值.我必须在引用对象之前填充这些值.所以我只是检查杰克逊是否有任何钩子,以便我可以在那里进行计算.例如,JAXB提供afterUnmarshal方法来自定义解组行为:
void afterUnmarshal(Unmarshaller u, Object parent)
Run Code Online (Sandbox Code Playgroud)
但我找不到关于定制杰克逊的类似信息.杰克逊是否提供了任何此类框架钩子来定制解组行为?
我试图在Spring中使用ResourceBundleMessageSource.这是我的项目结构:

这是xml配置:
<bean name="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
当我尝试加载应用程序上下文时,我收到以下异常:
Jun 7, 2012 2:44:00 PM org.springframework.context.support.ResourceBundleMessageSource getResourceBundle
WARNING: ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en_US
Exception in thread "main" org.springframework.context.NoSuchMessageException: No message found under code 'user.welcome' for locale 'en_US'.
at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:135)
at org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:1192)
at com.pramati.core.MessageResolver.getMessage(MessageResolver.java:19)
Run Code Online (Sandbox Code Playgroud)
如果我将资源包文件直接放在资源文件夹下,我没有收到此错误.它工作正常.有人可以通过将资源包放在src/main/resources的子目录中让我知道如何才能完成这项工作?
我们正在尝试在我们的应用程序中使用Hazelcast作为分布式缓存.这是我们的配置:
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd" xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
<name>sample_dev</name>
<password>dev@123</password>
</group>
<management-center enabled="false">http://localhost:8080/mancenter</management-center>
<properties>
<property name="hazelcast.logging.type">slf4j</property>
<property name="hazelcast.socket.bind.any">false</property>
</properties>
<serialization>
<serializers>
<global-serializer override-java-serialization="true">com.prasanth.common.KryoSerializer</global-serializer>
</serializers>
</serialization>
<network>
<join>
<multicast enabled="false"/>
<tcp-ip enabled="true">
<member-list>
<member>127.0.0.1:5701</member>
</member-list>
</tcp-ip>
</join>
<interfaces enabled="false">
<interface>192.168.3.*</interface>
</interfaces>
</network>
<map name="com.prasanth.cache.CachedAsset">
<in-memory-format>BINARY</in-memory-format>
<backup-count>1</backup-count>
<async-backup-count>1</async-backup-count>
<time-to-live-seconds>86400</time-to-live-seconds>
<max-idle-seconds>1200</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<max-size policy="PER_NODE">4500</max-size>
<merge-policy>com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy>
<!--<read-backup-data>true</read-backup-data>-->
<near-cache>
<in-memory-format>OBJECT</in-memory-format>
<cache-local-entries>true</cache-local-entries>
<time-to-live-seconds>86400</time-to-live-seconds>
<max-idle-seconds>1200</max-idle-seconds>
<invalidate-on-change>true</invalidate-on-change>
</near-cache>
</map>
</hazelcast>
Run Code Online (Sandbox Code Playgroud)
从文档中,我可以看到,每次调用Hazelcast时,都会涉及反序列化.因此,为了优化调用,我们使用Kryo作为默认序列化器并实现了近缓存.我们必须将每个大小为500KB的对象放入地图中,并且我们可以在内存中有大约400-500个这样的活动对象.我们经常在应用程序中使用缓存.
之前我们使用EhCache和JGroups配置缓存实现.操作速度非常快.但是当我们尝试使用Hazelcast时,我发现操作时间有很大差异.我可以说,Hazelcast不仅仅是一个缓存实现.但只是想知道为什么与EhCache(使用jgroups)相比,操作变得非常慢.我们的配置是否有问题?请指教!
另请注意,我正在单节点机器上测试它.
我试图了解PagingState如何与 Cassandra 中的 Statement 配合使用。我尝试使用一个示例,将几千条记录插入到数据库中,并尝试从数据库中读取相同的记录,并将获取大小设置为 10 并使用分页状态。这工作得很好。这是我的示例 junit 代码:
\n\n@Before\npublic void setup() {\n cassandraTemplate.executeQuery("create table if not exists pagesample(a int, b int, c int, primary key(a,b))");\n String insertQuery = "insert into pagesample(a,b,c) values(?,?,?)";\n PreparedStatement insertStmt = cassandraTemplate.getConnection().prepareStatement(insertQuery);\n for(int i=0; i < 5; i++){\n for(int j=100; j<1000; j++){\n cassandraTemplate.executeQuery(insertStmt, new Object[]{i, j, RandomUtils.nextInt()});\n }\n }\n}\n\n@Test\npublic void testPagination() {\n String selectQuery = "select * from pagesample where a=?";\n String pagingStateStr = null;\n for(int run=0; run<90; run++){\n ResultSet resultSet = …Run Code Online (Sandbox Code Playgroud)