可能重复:
Java泛型:为什么Map.get()忽略类型?
有人可以解释为什么使用Map定义
V put(K key,V value);
V get(Object key);
Run Code Online (Sandbox Code Playgroud)
为什么get没有定义为:
V get(K key)
Run Code Online (Sandbox Code Playgroud)
同样,为什么这些方法键入的Object,而不是K和V分别?
boolean containsKey(Object key); // Why not K?
boolean containsValue(Object value); // Why not V?
Run Code Online (Sandbox Code Playgroud)
这是一个向后兼容的东西(1.5之前的版本)?
我正在使用Disruptor框架,并且发现我的事件处理程序没有被调用.
这是我的设置代码:
private static final int BUFFER_SIZE = 1024 * 8;
private final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
private void initializeDisruptor() {
if (disruptor != null)
return;
disruptor =
new Disruptor<TwitterStatusReceivedEvent>(TwitterStatusReceivedEvent.EVENT_FACTORY, EXECUTOR,
new SingleThreadedClaimStrategy(BUFFER_SIZE),
new SleepingWaitStrategy());
disruptor.handleEventsWith(searchTermMatchingHandler)
.then(appendStatusHandler,updatePriceHandler).then(persistUpdatesHandler);
this.ringBuffer = disruptor.start();
}
Run Code Online (Sandbox Code Playgroud)
在其他地方,我发布了一些事件.我尝试过以下两种方法:
事件发布方法A:
private void handleStatus(final Status status)
{
long sequence = ringBuffer.next();
TwitterStatusReceivedEvent event = ringBuffer.get(sequence);
event.setStatus(status);
event.setSearchInstruments(searchInstruments);
ringBuffer.publish(sequence);
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我发现第一个EventHandler被调用,但除此之外从未发生任何事情.
事件发布方法B:
private void handleStatus(final Status status)
{
disruptor.publishEvent(new EventTranslator<TwitterStatusReceivedEvent>() {
@Override
public TwitterStatusReceivedEvent translateTo( …Run Code Online (Sandbox Code Playgroud) 我有一个从查询返回数组的资源,如下所示:
.factory('Books', function($resource){
var Books = $resource('/authors/:authorId/books');
return Books;
})
Run Code Online (Sandbox Code Playgroud)
是否可以将原型方法添加到从此查询返回的数组中?(注意,不要array.prototype).
例如,我想添加诸如hasBookWithTitle(title)集合之类的方法.
我最初是一个.NET人,最近在Java工作,发现我真的缺少LINQ to Objects,特别是对集合进行过滤.
Stack Overflow上的一些人回答了"LINQ for Java?" 问题只有一个字:
然而,在网站上它清楚地说明了"Pre-Beta",而且他们的代码一年多没有提交,所以我猜这个项目已经死了.
有人真的在使用它,和/或有任何经验吗?
第二个最常见的答案似乎是"使用Google Collections".这是最合适的Java方式吗?
干杯
马蒂
我无法让Hibernate在MySQL上执行批量插入.
我正在使用Hibernate 3.3和MySQL 5.1
从高层次来看,这就是正在发生的事情:
@Transactional
public Set<Long> doUpdate(Project project, IRepository externalSource) {
List<IEntity> entities = externalSource.loadEntites();
buildEntities(entities, project);
persistEntities(project);
}
public void persistEntities(Project project) {
projectDAO.update(project);
}
Run Code Online (Sandbox Code Playgroud)
这导致n个日志条目(每行1个),如下所示:
Hibernate:插入ProjectEntity(name,parent_id,path,project_id,state,type)值(?,?,?,?,?,?)
我希望看到这个被批处理,所以更新更高效.这个例程可能会导致生成数万行,并且每行数据包跳闸是一个杀手.
为什么不进行批量处理?(我的理解是,批处理插入在hibernate适当的地方应该是默认的).
我有以下内容hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/EJB</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<!-- Snip -->
Run Code Online (Sandbox Code Playgroud)
我用这条线消耗:
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Run Code Online (Sandbox Code Playgroud)
然后,在其他地方我尝试这样做:
SimpleSelect pkSelect = new SimpleSelect(Dialect.getDialect());
Run Code Online (Sandbox Code Playgroud)
导致以下异常:
org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
Run Code Online (Sandbox Code Playgroud)
注意,以下摘录自日志:
02:26:48,714 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
02:26:48,717 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
02:26:48,909 DEBUG Configuration:1387 - hibernate.dialect=org.hibernate.dialect.MySQLDialect
Run Code Online (Sandbox Code Playgroud)
有什么想法我做错了吗?
我正在努力让XPath定义为uniqueappversionid从以下XML 返回值:
<?xml version="1.0" encoding="UTF-8"?>
<manifest package="air.com.vzw.Foo"
android:versionCode="0"
android:versionName="0.0.0"
android:installLocation="auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="FooAIR">
<meta-data android:name="autoOrients" android:value="true" />
<meta-data android:name="fullScreen" android:value="false" />
<meta-data android:name="uniqueappversionid"
android:value="b1e1bfa8-20b4-4724-a9c3-34b79bc50b8d" />
<meta-data android:name="initialcontent" android:value="FooAIR.swf" />
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
更具体地说,我需要android:value从meta-data元素中获取属性的值android:name等于uniqueappversionid.

Charles的这张图片显示了一些非常有趣的信息:
我想更好地理解这些术语的实际含义.
即.查尔斯如何衡量请求持续时间?(在HTTP事务过程中,这是从何时到何时的时间?)同样对于响应.
还有request + response != Duration.剩下的服务器端处理时间是多少?
什么是延迟这里的衡量标准?
当有特定事件发生时,我正在调用一个远程服务来加载产品的定价数据.一旦加载,产品定价就会被广播,供另一个消费者在其他地方处理.
我不想在每个事件上调用远程服务,而是将事件批量分组,然后一次性发送.
我基于聚合器拼凑了以下模式.虽然它有效但很多都有"闻起来" - 特别是我的SimpleCollatingAggregator.我是Spring Integration和EIP的新手,并且怀疑我是在滥用组件.
通过调用下面的方法,我的代码在代码的其他地方触发@Gateway:
public interface ProductPricingGateway {
@Gateway(requestChannel="product.pricing.outbound.requests")
public void broadcastPricing(ProductIdentifer productIdentifier);
}
Run Code Online (Sandbox Code Playgroud)
然后将其连接到聚合器,如下所示:
<int:channel id="product.pricing.outbound.requests" />
<int:channel id="product.pricing.outbound.requests.batch" />
<int:aggregator input-channel="product.pricing.outbound.requests"
output-channel="product.pricing.outbound.requests.batch" release-strategy="releaseStrategy"
ref="collatingAggregator" method="collate"
correlation-strategy-expression="0"
expire-groups-upon-completion="true"
send-partial-result-on-expiry="true"/>
<bean id="collatingAggregator" class="com.mangofactory.pricing.SimpleCollatingAggregator" />
<bean id="releaseStrategy" class="org.springframework.integration.aggregator.TimeoutCountSequenceSizeReleaseStrategy">
<!-- Release when: 10 Messages ... or ... -->
<constructor-arg index="0" value="10" />
<!-- ... 5 seconds since first request -->
<constructor-arg index="1" value="5000" />
</bean>
Run Code Online (Sandbox Code Playgroud)
这是聚合器实现:
public class SimpleCollatingAggregator {
public List<?> collate(List<?> input) …Run Code Online (Sandbox Code Playgroud) 是否有关于控制器声明的既定惯例?(或任何形式的模块级配置).
我观察到两种不同的使用方法:
var shoppingCartModule = angular.module('ShoppingCart',[])
shoppingCartModule.controller('CheckoutCtrl', function($scope) { ... });
Run Code Online (Sandbox Code Playgroud)
VS
angular.module('ShoppingCart').controller('CheckoutCtrl', function($scope) { ... });
Run Code Online (Sandbox Code Playgroud)
这两种方法之间有什么好处吗?此外,是否有一个首选的(或新兴的)惯例?
我对具有许多模块的非平凡应用程序的好处特别感兴趣,其中控制器和模块的声明可能跨越许多文件.
java ×6
angularjs ×2
hibernate ×2
collections ×1
generics ×1
http ×1
javascript ×1
mysql ×1
orm ×1
performance ×1
spring ×1
xml ×1
xpath ×1