小编pra*_*upd的帖子

使用Executors.newSingleThreadExecutor()的优点

使用的优点是什么

Executors.newSingleThreadExecutor().submit(job);
Run Code Online (Sandbox Code Playgroud)

job.run();
Run Code Online (Sandbox Code Playgroud)

哪个jobRunnable类的实例.

java multithreading

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

如何更改生成的表中的列顺序(grails约束不使用mongodb插件)

我正在使用带有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)

任何想法我怎么能改变这个以获得我在约束中设置的工作顺序?

grails scaffolding mongodb

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

查询@ElementCollection JPA

我有一个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)

所以,我的数据库Tabletransaction_properties

mysql> desc transaction_properties;
+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| p_id          | bigint(20)   | NO   | PRI |         |       | …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa hibernate-criteria

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

hql 加入@CollectionTable

我有一个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特定KEYService.tags

hql接合ServiceService.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)

hibernate hql jpql

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

Cassandra12错误 - 无法打开不兼容的SSTable!当前版本ic

用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

cassandra

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

使用JSON模式和ElasticSearch Java API添加类型映射

是否可以使用模式使用Java API mapping向ElasticSearch 添加类型?IndexJSON

我知道ElasticSearch使用第一个文档来创建一个mapping,因此我可以使用json模式增强我的第一个文档.但我想在索引文档之前创建类型.

java elasticsearch

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

使用hadoop运行jar时的NoSuchMethodError Sets.newConcurrentHashSet()

我正在使用带有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 hadoop jar cassandra

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

Java 8 lambdas在列表流上使用if else

我有一个以下生产就绪的java 8方法; 哪一个

  • 迭代列表
  • 基于谓词的过滤器
  • 如果找到基于过滤器的0方法,则抛出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)

java lambda

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

Intellij 15错误:找不到libjava.dylib

我在我的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/ …

java intellij-idea

5
推荐指数
2
解决办法
1705
查看次数

scala 全局 ExecutionContext 与 ExecutionContextExecutorService

我正在使用默认全局上下文和我自己的 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)

scala future executorservice

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