使用的优点是什么
Executors.newSingleThreadExecutor().submit(job);
Run Code Online (Sandbox Code Playgroud)
比
job.run();
Run Code Online (Sandbox Code Playgroud)
哪个job是Runnable类的实例.
我正在使用带有mongodb插件的Grails 2.1.1.我在生成列表中更改列的顺序时遇到问题.正如Grails脚手架指南所说,您只需要在约束块中正确排序属性.
我的域名:
class Section {
String idName
String visible
String required
String name
String bold
static embedded = ['question']
List<Question> questions
static hasMany = [questions : Question]
static constraints = {
idName (blank: false)
name (blank: false)
visible (blank: false)
required (blank: false)
bold (blank: false)
}
@Override
public String toString() {
name
}
}
Run Code Online (Sandbox Code Playgroud)
但列仍按字母顺序排序.我正在使用静态脚手架,所以在更改约束后我使用grails generate-all *命令并覆盖所有文件.
是的,我尝试清理和编译代码,还清理和重启服务器(这与STS集成)和清理浏览器缓存.mongo数据库有问题(hibernate插件是否已卸载)?
之后我还安装了grails模板.在list.gsp中有一行具有排序属性:
Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[]))
Run Code Online (Sandbox Code Playgroud)
任何想法我怎么能改变这个以获得我在约束中设置的工作顺序?
我有一个Entity Transaction如下:
@Entity
class Transaction extends AbstractEntity<Long>{
private static final long serialVersionUID = 7222139865127600245L;
//other attributes
@ElementCollection(fetch = FetchType.EAGER, targetClass = java.lang.String.class)
@CollectionTable(name = "transaction_properties", joinColumns = @JoinColumn(name = "p_id"))
@MapKeyColumn(name = "propertyKey")
@Column(name = "propertyValue")
private Map<String, String> properties;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
所以,我的数据库Table为transaction_properties是
mysql> desc transaction_properties;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| p_id | bigint(20) | NO | PRI | | | …Run Code Online (Sandbox Code Playgroud) 我有一个Service包含tags以下集合的域:
@Entity
public class Service extends AbstractEntity<Long> {
private static final long serialVersionUID = 9116959642944725990L;
@ElementCollection(fetch = FetchType.EAGER, targetClass = java.lang.String.class)
@CollectionTable(name = "service_tags", joinColumns = @JoinColumn(name = "s_id"))
@Column(name = "tag")
private Set<String> tags;
}
Run Code Online (Sandbox Code Playgroud)
我想选择Service小号with特定KEY的Service.tags。
hql接合Service到Service.tags是如下:
select s from Service s INNER JOIN s.tags t where s.status=0 and (s.serviceType=9 or t.tag in ('College'))
Run Code Online (Sandbox Code Playgroud)
但是,上面的 hql 返回给我以下异常:
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: cannot …Run Code Online (Sandbox Code Playgroud) 用homebrew安装cassandra12之后,退出并显示以下消息:
java.lang.RuntimeException: Can't open incompatible SSTable! Current version ic, found file: /usr/local/var/lib/cassandra/data/system/schema_keyspaces/system-schema_keyspaces-jb-9
Computer-computer:desktop $ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Run Code Online (Sandbox Code Playgroud)
已安装的版本是 cassandra 1.2.11
是否可以使用模式使用Java API mapping向ElasticSearch 添加类型?IndexJSON
我知道ElasticSearch使用第一个文档来创建一个mapping,因此我可以使用json模式增强我的第一个文档.但我想在索引文档之前创建类型.
我正在使用带有hadoop 2.2.0的cassandra-all 2.0.7 api .
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>zazzercode</groupId>
<artifactId>doctorhere-engine-writer</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>DoctorhereEngineWriter</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cassandra.version>2.0.7</cassandra.version>
<hector.version>1.0-2</hector.version>
<guava.version>15.0</guava.version>
<hadoop.version>2.2.0</hadoop.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>zazzercode.DiseaseCountJob</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
<version>${hector.version}</version>
<exclusions>
<exclusion>
<artifactId>org.apache.thrift</artifactId>
<groupId>libthrift</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>${cassandra.version}</version>
<exclusions>
<exclusion>
<artifactId>libthrift</artifactId>
<groupId>org.apache.thrift</groupId>
</exclusion>
</exclusions>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我有一个以下生产就绪的java 8方法; 哪一个
RuntimeException消息1.RuntimeException消息2.我用90s的一些lambda魔法达到了我想要的效果if else......
private Method getEventHandler(Class listener, Class<? extends Event> event) {
List<Method> methods = asList(listener.getMethods())
.stream()
.filter(method -> shouldHandleEvent(method, event))
.collect(Collectors.toList());
if ( methods.size() == 0 ) {
throw new RuntimeException("No event handlers");
} else if ( methods.size() > 1 ) {
throw new RuntimeException("More than one handler.");
}
return methods.get(0);
}
private boolean shouldHandleEvent(Method method, Class<? extends Event> event) {
return method.getParameterCount() ==1 &&
method.getParameterTypes()[0].isAssignableFrom(event); …Run Code Online (Sandbox Code Playgroud) 我在我的macos中安装了Intellj 15.运行它时会抛出以下错误.
$ /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/MacOS/idea
2016-05-21 18:07:53.774 idea[1307:51782] Value of IDEA_JDK: (null)
2016-05-21 18:07:53.778 idea[1307:51795] fullFileName is: /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions
2016-05-21 18:07:53.778 idea[1307:51795] fullFileName exists: /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions
2016-05-21 18:07:53.778 idea[1307:51795] Value of IDEA_VM_OPTIONS is (null)
2016-05-21 18:07:53.778 idea[1307:51795] Processing VMOptions file at /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions
2016-05-21 18:07:53.779 idea[1307:51795] Done
Error: could not find libjava.dylib
Failed to GetJREPath()
2016-05-21 18:07:53.779 idea[1307:51795] JNI_CreateJavaVM (/Applications/IntelliJ IDEA 15 CE.app/Contents/jre/jdk) failed: 4294967295
Run Code Online (Sandbox Code Playgroud)
我将JAVA_HOME设置为
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/"
Run Code Online (Sandbox Code Playgroud)
我libjava.dylib在/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ …
我正在使用默认全局上下文和我自己的 scala Futures ExecutionContext。
我很好奇global context所有执行后如何关闭。因为如果我创建自己的,ExecutionContext我必须手动关闭。
例子,
1)使用全局executionContext,
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
object ParallelTasksWithGlobalExecutionContext {
private val data: Iterable[Input] = Iterable("data1", "data2", "data3")
def main(args: Array[String]): Unit = {
val f: Future[Unit] = Future.traverse(data) { d =>
println(s"[${Thread.currentThread().getName}]-Firing $d")
processData(d)
} map { processed =>
processed.foreach(p => println(s"""[${Thread.currentThread().getName}]-$p"""))
}
Await.result(f, Duration.Inf)
}
type Input = String
type Output = String
def processData: (Input => Future[Output]) = data => {
Future {
Thread.sleep(5000) …Run Code Online (Sandbox Code Playgroud)