akka actor模型和java thread模型各有什么优势

akka actor模型和java thread模型各有什么优势,第1张

1) akka actor背后也是通过线程池来执迅尘早行的。actor与thread不是一个维度的事情,actor比thread更抽象,更偏上层,它只是定义了一种机制,怎么实现或底层用什么实现是另一回事。

2) 实际上actor更容易驾驭(框架帮你屏蔽了很多底亩雀层的事情),thread在并发下兼顾性能和正确性有很多技巧,要兄埋用好还没那么容易。

在Java应用程序中调用Kettle的Transformation

package com.ggd543.kettle.trans

import org.pentaho.di.core.util.EnvUtil

import org.pentaho.di.core.KettleEnvironment

import org.pentaho.di.trans.{Trans, TransMeta}

/**

*

* User: 刘永健

* Date: 12-3-8

* Time: 下午12:14

* To change this template use File | Settings | File Templates.

*/

object TransDemo extends App {

execTrans(args(0)) // ktr文件的全路径

def execTrans(fileName: String) {

KettleEnvironment.init()

EnvUtil.environmentInit()

val transMeta = new TransMeta(fileName)

val trans = new Trans(transMeta)

trans.execute(null) // you can pass arguments instead of null

trans.waitUntilFinished()

if (trans.getErrors >0) {

throw new RuntimeException("There were errors during transformation execution")

}

}

}

<?xml version="1.0" encoding="UTF-8"?>

<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>kettledemo</groupId>

<artifactId>kettledemo</artifactId>

<version>1.0</version>

<dependencies>

<!-- Test -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.8.1</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.scala-tools.testing</groupId>

<artifactId>specs_2.9.1</artifactId>

<version>1.6.9</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.scalatest</groupId>

<artifactId>scalatest_2.9.1</artifactId>

<version>1.6.1</version>

<scope>test<蚂消誉桥亩/scope>

</dependency>

<dependency>

<groupId>com.typesafe.akka</groupId>

<artifactId>akka-actor</artifactId>

<version>2.0</version>

</dependency>

<dependency>

<groupId>com.typesafe.akka</groupId>

<artifactId>akka-testkit</artifactId>

<version>2.0</version>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.6</source>

<target>1.6</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

</plugins>

</build>

<profiles>

<profile>

<id>pentaho</id>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

<properties>

<pentaho.kettle.version>4.2.1.1</pentaho.kettle.version>

</properties>

<dependencies>

<dependency>

<groupId>pentaho-kettle</groupId>

<artifactId>kettle-core</artifactId>

<version>${pentaho.kettle.version}</version>

</dependency>

<dependency>

<groupId>pentaho-kettle</groupId>

<artifactId>kettle-db</artifactId>

<version>${pentaho.kettle.version}</version>

</dependency>

<dependency>

<groupId>pentaho-kettle</groupId>

<artifactId>kettle-engine</artifactId>

<version>${pentaho.kettle.version}</version>

</dependency>

<dependency>

<groupId>pentaho</groupId>

<artifactId>pentaho-hdfs-vfs</artifactId>

<version>1.0.1</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.16</version>

</dependency>

<dependency>

<groupId>pentaho-kettle</groupId>

<artifactId>kettle-test</artifactId>

<version>${pentaho.kettle.version}</version>

<scope>test</scope>

</dependency>

</dependencies>

<repositories>

<repository>

<id>pentaho</id>

<name>Pentaho Repository</name>

<url>http://repo.pentaho.org/artifactory/pentaho/</url>

</repository>

</repositories>

</profile>

<profile>

<id>scala</id>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

<properties>

<scala.version>2.9.1</scala.version>

</properties>

<repositories>

<repository>

<id>typesafe</id>

<name>Typesafe Repository</name>

<url>http://repo.typesafe.com/typesafe/releases/</url>

</repository>

</repositories>

<dependencies>

<dependency>

<groupId>org.scala-lang</groupId>

<artifactId>scala-compiler</artifactId>

<version>${scala.version}</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.scala-lang</groupId>

<artifactId>scala-library</artifactId>

<version>${scala.version}</version>

</dependency>

<dependency>

<groupId>org.scala-lang</groupId>

<artifactId>scala-swing</artifactId>

<version>${scala.version}</version>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.scala-tools</groupId>

<artifactId>maven-scala-plugin</artifactId>

<executions>

<execution>

<goals>

<goal>compile</goal>

<goal>testCompile</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

</profile>

</profiles>

</project>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12365994.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存