如果我想调用多个C函数,每个函数取决于前一个函数的结果,是否最好创建一个处理三个调用的包装器C函数?它会花费与使用Haskell FFI而不转换类型相同的成本吗?
假设我有以下Haskell代码:
foo :: CInt -> IO CInt
foo x = do
a <- cfA x
b <- cfB a
c <- cfC c
return c
Run Code Online (Sandbox Code Playgroud)
每个函数cf*都是C调用.
在性能方面,创建单个C函数cfABC并在Haskell中只进行一次外部调用会更好吗?
int cfABC(int x) {
int a, b, c;
a = cfA(x);
b = cfB(a);
c = cfC(b);
return c;
}
Run Code Online (Sandbox Code Playgroud)
Haskell代码:
foo :: CInt -> IO CInt
foo x = do
c <- cfABC x
return c
Run Code Online (Sandbox Code Playgroud)
如何衡量Haskell的C调用的性能成本?不是C函数本身的成本,而是从Haskell到C的"上下文切换"的成本.
使用此代码设置类路径
AWSCredentialsProvider credentialsProvider = new ClasspathPropertiesFileCredentialsProvider();
ec2 = new AmazonEC2Client(credentialsProvider);
Run Code Online (Sandbox Code Playgroud)
以下是AwsCredentials.properties文件的格式
# Fill in your AWS Access Key ID and Secret Access Key
# http://aws.amazon.com/security-credentials
accessKey = keyHere
secretKey = secretKeyHere
Run Code Online (Sandbox Code Playgroud)
以下是我得到的例外情况
Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load AWS credentials from the /AwsCredentials.properties file on the classpath
at com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider.getCredentials(ClasspathPropertiesFileCredentialsProvider.java:81)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:8359)
Run Code Online (Sandbox Code Playgroud) 例如,考虑下面的代码捕捉:
public static final int a;
public static final int b;
static {
a = 8; // it's working
Test.b = 10; // compilation error Test.b cannot be assigned.
}
Run Code Online (Sandbox Code Playgroud)
为什么我们不能Test.b = 10;在Test类本身的静态块中使用?没有班级名称,它工作正常.
这背后有什么理由吗?
我们使用Flyway迁移数据库模式,我们已经有超过100个迁移脚本.
一旦我们将多个迁移"压缩"到单个第一版迁移中,这在开发期间就可以了,因为我们删除并重新创建模式.但是在生产中这不起作用,因为Flyway无法验证迁移.
在这种情况下,我找不到任何文档或最佳做法.问题是文件数量不断增加,我不希望每次都看到数千个迁移文件,基本上如果生产已经是最新版本.我的意思是,版本号低于生产版本的迁移脚本与我们无关,如果我们可以将这些文件压缩到单个迁移中,那将是非常棒的.
我们正在使用MySQL.
我们该如何处理?
我正在使用EclipseLink(2.5.1,也尝试过2.5.2-M1)构建一个java SE 8(oracle 1.8.0-b129)应用程序,并且有一个实体类,即使被正确注释,也只是被EclipeLink忽略了.在persistence.xml文件中引用.日志显示没有提及类,没有为它生成模式,等等.使用实体给出'抽象模式类型未知'错误.
我想我终于找到了原因,并认为我会分享.显然,EclipseLink不喜欢带有lambda表达式的类.这是一个简单的类来重现问题:
@Entity
public class LambdaEntity {
@Id
private Integer id;
public void theLambda() {
Arrays.asList(1, 2, 3).stream().filter(m -> m == 2);
}
}
Run Code Online (Sandbox Code Playgroud)
lambda表达式甚至不必使用持久属性,它在类中的简单存在就足够了.有谁知道是什么原因引起的?我猜测EclipeLink会对生成的字节码产生阻塞,但我发现很奇怪它会默默地忽略该类.
如果您尝试在与其他实体的关联中使用此实体,EclipseLink将提供错误,指出该实体未在该persistence.xml文件中定义.stacktrace的一部分:
Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@3b9a45b3
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [hcm-test] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence …Run Code Online (Sandbox Code Playgroud) 我使用Log4j RollingFileAppender来创建基于大小的日志轮换.
如何将其配置为在旋转前记录每个文件一段时间?
例如,每个日志文件包含一小时的日志,在每小时的顶部旋转?
我使用Properties对象(而不是log4j.properties文件)在Java中以编程方式配置Log4j
Apache Portable Runtime是编译某些应用程序的依赖项.
./configure说这apr-1是必要的.
如何在Ubuntu上安装它?
OrientDB官方网站说:
在通用硬件上,每秒最多可存储150,000个文档,每天可存储10亿个文档.大图可以在几毫秒内加载,而无需执行昂贵的JOIN,例如Relational DBMS.
但是,执行以下代码表明,插入150000个简单文档需要大约17000ms.
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
public final class OrientDBTrial {
public static void main(String[] args) {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/foo");
try {
db.open("admin", "admin");
long a = System.currentTimeMillis();
for (int i = 1; i < 150000; ++i) {
final ODocument foo = new ODocument("Foo");
foo.field("code", i);
foo.save();
}
long b = System.currentTimeMillis();
System.out.println(b - a + "ms");
for (ODocument doc : db.browseClass("Foo")) {
doc.delete();
}
} finally {
db.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的硬件:
简单的问题.
这编译:
module Example where
import Network
port :: PortID
port = PortNumber 3001
Run Code Online (Sandbox Code Playgroud)
而这不是:
module Example where
import Network (PortID, PortNumber)
port :: PortID
port = PortNumber 3001
Run Code Online (Sandbox Code Playgroud)
GHC说:
Example.hs:6:8: Not in scope: data constructor `PortNumber'
Run Code Online (Sandbox Code Playgroud)
为什么?
showInt :: Int -> String
showInt x = show x
Run Code Online (Sandbox Code Playgroud)
上面的代码是调用show传递Int字典还是直接调用Show Int实例上声明的函数?
我的意思是,GHC是否在可能的情况下从生成的代码中删除了多态间接?
java ×5
haskell ×3
amazon-ec2 ×1
apr ×1
c ×1
eclipselink ×1
ffi ×1
final ×1
flyway ×1
ghc ×1
java-8 ×1
lambda ×1
log4j ×1
orientdb ×1
performance ×1
polymorphism ×1
static ×1
static-block ×1
ubuntu ×1