我想写一个socket.从阅读网络IO,在我看来,写入它的最佳方式是做这样的事情:
OutputStream outs=null;
BufferedWriter out=null;
out =
new BufferedWriter(
new OutputStreamWriter(new BufferedOutputStream(outs),"UTF-8"));
Run Code Online (Sandbox Code Playgroud)
在BufferedWriter将缓冲输入到OutputStreamWriter这是推荐的,因为它防止了从作家启动每个字符的编码器.
然后,BufferedOutputStream将缓冲来自的字节,Writer以避免一次将一个字节放到网络上.
它看起来有点像矫枉过正,但它似乎都有帮助吗?感谢任何帮助..
编辑:从javadoc上OutputStreamWriter:
每次调用write()方法都会导致在给定字符上调用编码转换器.生成的字节在写入底层输出流之前累积在缓冲区中.可以指定此缓冲区的大小,但默认情况下,它足够大,可用于大多数用途.请注意,传递给write()方法的字符不会被缓冲.
为了获得最高效率,请考虑在BufferedWriter中包装OutputStreamWriter,以避免频繁的转换器调用.例如:
Writer out = new BufferedWriter(new OutputStreamWriter(System.out));
Run Code Online (Sandbox Code Playgroud) 我有一份每小时运行一次的工作,我正在使用Spring的@scheduled cron来安排它.
如果工作需要一个多小时,我从如何防止Spring中的重叠计划中了解到?第一份工作正在运行时,下一份工作不会启动.
但这是否意味着它将在第一份工作完成后启动,或者是否错过了机会?
如果我有一个需要10个小时的工作,那么所有错过的cron作业是否会排队,然后在第一个作业在10个小时后完成时逐个执行,或者只是第一个作业运行?
谢谢!
我在eclipse中运行tomcat中的一些servlet代码.它一直很好,但今天我得到了错误Unable to locate Spring NamespaceHandler for XML schema namespace.完整错误如下所示:
SEVERE: Allocate exception for servlet RunServlet
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: class path resource [spring/dao.xml]
Run Code Online (Sandbox Code Playgroud)
我已经看过有关此错误的其他问题,但我并不理解答案.
当我查看目标库时,我可以看到它spring-tx-3.0.5.RELEASE.jar在WEB-INF/lib.
谁能帮我吗?
非常感谢!
编辑:dao.xml开始:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
Run Code Online (Sandbox Code Playgroud)
编辑:不确定这是否相关,但我正在研究mac book pro,最新的mac更新更新到Java 1.6,我刚刚将我的Java首选项切换到1.6.
编辑:我也在Tomcat日志中收到以下消息,但我认为我以前收到它并且我认为它不相关,但以防万一:
INFO: Starting Servlet Engine: Apache Tomcat/7.0.14
Jul 6, 2011 11:59:55 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/Users/bw/Documents/workspace2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/core/WEB-INF/lib/servlet-api-2.5.jar) - jar …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用cxf,所以这可能是一个新手的错误..
我正在完成这本书的实际治理,并下载了示例项目.
当我使用cxf从wsdl构建源代码时,它会将源代码放在eclipse的'target'目录中.但这些是它创建的java文件,并且编译器似乎没有看到它们,因此构建需要这些文件的应用程序会因编译器错误而失败.
我应该将'target'中的generated-sources目录添加到构建路径中吗?
非常感谢!
编辑:彻底混淆.这是pom
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange>[1.7,)</versionRange>
<goals>
<goal>add-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute></execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.cxf</groupId>
<artifactId>
cxf-codegen-plugin
</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>wsdl2java</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute></execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source> …Run Code Online (Sandbox Code Playgroud) 所以我开始学习神经网络,但我发现很难找出基础知识.感谢任何人都能提供的任何帮助..
1)是否有应输入神经元的标准值?例如,如果一个神经元有5个传入连接,那么每个连接是否应该提供a)0到1之间的连续值?b)0或1?c)还有别的吗?
2)如果你使用tanh的激活函数,这意味着如果点积输入达到约3(tanh(3)= .995),神经元将开始输出1.如果我有一个20个隐藏节点的层,这意味着权重需要很小 - 大约.05标记 - 如果我们要避免最大化激活功能?那么我们为什么要将起始权重设置在-1和1之间呢?最好从非常小的开始?
3)神经元的输出应该是多少?a)介于0和1之间的值?b)0或1?c)还有别的吗?一些人工神经网络的神经元输出在-1和1之间(我想我已经看到了吗?)
4)似乎输入层和输出层的规则发生了变化?对于输入层,我猜你必须将输入数据编码为合适的格式.这总是意味着编码为0到1之间的值吗?同样对于输出层,大概你必须按下你的输出值到有用的东西?因此,如果您的ANN输出0到1之间的连续值,并且您想要YES或NO,那么您可以制定一个规则<0.5为NO且> 0.5为YES.它是如何工作的?
5)将标量输入值编码为二进制是否有缺点?似乎有点奇怪,大数字可能有一个1作为最后一位,但是这个数字+ 1最后一位有0?是否有更连续的编码值更好的方法?
对不起,很多问题..感谢任何答案.谢谢!
在源文件中:
\naddV1 x y = (if x > y then y else x) + 5\naddV2 = \\x -> \\y -> (if x > y then y else x) + 5\nRun Code Online (Sandbox Code Playgroud)\n在 ghci 中:
\nghci> :l h.hs\nghci> addV1 4.5 10\n\n<interactive>:1083:1: warning: [-Wtype-defaults]\n \xe2\x80\xa2 Defaulting the following constraints to type \xe2\x80\x98Double\xe2\x80\x99\n (Show a0) arising from a use of \xe2\x80\x98print\xe2\x80\x99 at <interactive>:1083:1-12\n (Ord a0) arising from a use of \xe2\x80\x98it\xe2\x80\x99 at <interactive>:1083:1-12\n (Fractional a0)\n arising from a use of \xe2\x80\x98it\xe2\x80\x99 …Run Code Online (Sandbox Code Playgroud) 我对以下内容感到困惑:
class A(val s: String) {
def supershow {
println(s)
}
}
class B(override val s: String) extends A("why don't I see this?"){
def show {
println(s)
}
def showSuper {
super.supershow
}
}
object A extends App {
val b = new B("mystring")
b.show
b.showSuper
}
Run Code Online (Sandbox Code Playgroud)
我在期待:
mystring
why don't I see this?
Run Code Online (Sandbox Code Playgroud)
但我得到:
mystring
mystring
Run Code Online (Sandbox Code Playgroud)
在java中,如果你覆盖超级类中的变量或"影子"变量,那么超类就有自己的变量.但是在这里,即使我认为我使用不同的字符串显式初始化父级,父级也会设置为与子类相同的值?
当我.json在 PyCharm 中创建一个文件并放入一些 JSON 时,我希望它按照下面显示的格式对其进行格式化File > Settings > Editor > Code Style > JSON.
但相反,我的代码保持原样 - 例如,同一行上有多个 JSON 键值对,如下所示:
{"just a test": "does this work","this should format": "but it doesn't"}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点,当我打开一个 .json用 PyCharm文件时,它的格式很好?
我已经检查过了 .json文件在编辑器 -> 文件类型对话框中是否关联,并且编辑器选项卡正确具有 JSON 图标,因此 PyCharm 知道它是一个 JSON 文件。
有没有我必须点击的组合键才能让它漂亮地格式化或其他什么?
假设我有一个采用 Integer 值 ByRef 的函数,如下所示:
Function myFunc(ByRef funcVal As Integer)
funcVal = funcVal + 1
End Function
Run Code Online (Sandbox Code Playgroud)
假设我这样称呼它:
Dim myVal as Integer
myVal = 5
Call myFunc(myVal)
Run Code Online (Sandbox Code Playgroud)
据我了解,计算机已为我的myVal变量分配了空间,并将值 5 放入该空间中。当我调用 时myFunc,计算机基本上会将指向该位置的指针传递给myFunc,因此当myFunc递增 时funcVal,它实际上是在递增同一位置,因此myVal也递增。
但是如果我像这样调用 myFunc 会发生什么:
Call myFunc(5)
Run Code Online (Sandbox Code Playgroud)
计算机是否仍然给出myFunc一个指针,如果是,则指向什么指针?或者它是否必须分配一些新空间funcVal(而不是像myVal我之前的示例中那样仅使用相同的空间)?
我想这里还有一个相关的问题 - VBA 如何处理代码中的文字值?
非常感谢!
我在理解函数文字中的下划线时遇到了麻烦.
val l = List(1,2,3,4,5)
l.filter(_ > 0)
Run Code Online (Sandbox Code Playgroud)
工作良好
l.filter({_ > 0})
Run Code Online (Sandbox Code Playgroud)
工作良好
l.filter({val x=1; 1+_+3 > 0}) // ie you can have multiple statements in your function literal and use the underscore not just in the first statement.
Run Code Online (Sandbox Code Playgroud)
工作良好
但是:
l.filter({val x=_; x > 0})
e>:1: error: unbound placeholder parameter
l.filter({val x=_; x > 0})
Run Code Online (Sandbox Code Playgroud)
我无法将_变量分配给变量,即使以下是合法函数文字:
l.filter(y => {val x=y; x > 0})
Run Code Online (Sandbox Code Playgroud)
工作良好.
是什么赋予了?我的'val x = _'被解释为别的吗?谢谢!
有人可以帮我理解以下内容吗?如果我创建元素的树状图,scala 似乎决定我的比较方法也确定元素的相等性,因此根据“比较”方法删除相同的元素。我并不期待这一点,因为如果我没有覆盖它,平等仍然应该根据对象平等来定义?
import scala.collection.mutable._
class A(val num: Int) extends Ordered[A] {
def compare (that: A) = {
this.num - that.num
}
override def toString() = {
num+""
}
}
object A {
def main(args: Array[String]) = {
val mySet = new TreeSet[A]()
mySet += new A(3)
mySet += new A(2)
mySet += new A(1)
mySet += new A(3)
mySet += new A(2)
mySet += new A(1)
mySet.foreach(println)
}
}
Run Code Online (Sandbox Code Playgroud)
给
1
2
3
Run Code Online (Sandbox Code Playgroud)
不是预期的(由我)
1
1
2
2
3
3
Run Code Online (Sandbox Code Playgroud) 有人可以澄清以下代码的行为吗?
scala> val map = new collection.mutable.LinkedHashMap[String,collection.mutable.ArrayBuffer[String]]()
map: scala.collection.mutable.LinkedHashMap[String,scala.collection.mutable.ArrayBuffer[String]] = Map()
scala> val arr = map.getOrElse("Hi",None)
arr: Serializable with Equals = None
Run Code Online (Sandbox Code Playgroud)
为什么类型为Serializable的arr与Equals而不是ArrayBuffer [String]?
非常感谢!