我们有以下html标记:
<div id="parent" class="parent">
<div id="child" class="child">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和相应的CSS样式:
.parent{
border-style: solid;
border-color: green;
border-bottom: solid 10px;
background:grey;
width: 300px;
height: 300px;
padding: 10px;
}
.child{
border: 20px solid;
background: aqua;
height: 50px;
margin: 10px;
}
Run Code Online (Sandbox Code Playgroud)
.parent {
border-style: solid;
border-color: green;
border-bottom: solid 10px;
background: grey;
width: 300px;
height: 300px;
padding: 10px;
}
.child {
border: 20px solid;
background: aqua;
height: 50px;
margin: 10px;
}
Run Code Online (Sandbox Code Playgroud)
<div id="parent" class="parent">
<div id="child" class="child">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我们可以看到孩子的边框颜色是黑色,但我没有明确定义这种颜色.
如何将此默认颜色更改为绿色?
这是我的hibernate映射:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Entities.Product" table="products">
<id column="name" name="name" type="java.lang.String">
<generator class="increment"/>
</id>
<property column="cost" name="cost" type="java.lang.Integer"/>
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
该表由两列组成:name VARCHAR(20), cost Integer
.
控制器:
@Controller
public class ProductController {
@RequestMapping("/products.htm")
public String getAllProducts() throws SQLException
{
ProductDAOImpl mapping = new ProductDAOImpl();
Product p = new Product();
p.setCost(1000);
p.setName("????????");
mapping.addProduct(p);
return "index";
}
}
Run Code Online (Sandbox Code Playgroud)
addProduct方法:
public void addProduct(Product product) throws SQLException {
Session session = Hibernate.util.HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(product);
session.getTransaction().commit(); …
Run Code Online (Sandbox Code Playgroud) 我正在阅读J. Bloch的有效Java,现在我正在关于外来方法的部分.
我正在尝试理解Java并发中的外来方法及其可能造成的危害.正如他所说,我们基本上不知道外星人的方法可以做什么,我们可能最终陷入僵局.我试图重现这样一个死锁行为编写以下简单的应用程序(为简单起见,外来方法在同一个类中):
public class App {
private static StringBuffer lines = new StringBuffer();
public static void modifyLines(){
System.out.println("Invocation modifyLines() started by " + Thread.currentThread().getName());
synchronized (lines) {
System.out.println("Entering modifyLines() synchronized " + Thread.currentThread().getName());
lines.append("Modified");
}
}
public static void main(String[] args) throws InterruptedException {
synchronized (lines) {
System.out.println("Entering main() synchronized by " + Thread.currentThread().getName());
alienMethod();
}
}
public static void alienMethod(){
ExecutorService es = Executors.newSingleThreadExecutor();
es.submit(new Runnable() {
@Override
public void run() {
modifyLines();
}
});
es.shutdown();
}
} …
Run Code Online (Sandbox Code Playgroud) 我尝试了以下正则表达式:
const static char * regex_string = "([a-zA-Z0-9]+).*";
void find_first(const std::string str);
int main(int argc, char ** argv)
{
find_first("0s7fg9078dfg09d78fg097dsfg7sdg\r\nfdfgdfg");
}
void find_first(const std::string str)
{
std::cout << str << std::endl;
std::regex rgx(regex_string);
std::smatch matcher;
if(std::regex_match(str, matcher, rgx))
{
std::cout << "Found : " << matcher.str(0) << std::endl;
} else {
std::cout << "Not found" << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我预计正则表达式将是完全正确的,并且将找到该组.但事实并非如此.为什么?如何匹配c ++正则表达式中的换行符?在Java中它工作正常.
我写了以下简单的程序:
import java.util.{Set => JavaSet}
import java.util.Collections._
object Main extends App {
def test(set: JavaSet[String]) = ()
test(emptySet()) //fine
test(emptySet) //error
}
Run Code Online (Sandbox Code Playgroud)
并且真的很惊讶最后一行test(emptySet)
没有编译.为什么?有什么区别test(emptySet())
?我认为在Scala中我们可以在这种情况下自由省略括号.
我正在使用JNI来允许C代码卸载一些最好用Java完成的工作.在这个问题中,我试图链接libjvm和libjli库以使我的代码工作,但现在我在质疑我是否需要JLI库.
我找不到任何明确说明JLI库目的的文档.
这个其他的SO问题暗示JLI是一些OSX passthrough库:
#elif defined(__APPLE__)
// jli needs to be loaded on OSX because otherwise the OS tries to run the system Java
Run Code Online (Sandbox Code Playgroud)
和这个博客一样:
在OS X上进行编译时,在jvm库之前链接jli库非常重要
我的问题:
我试图通过cats.effect.IO
例子来理解异步计算并得到一些误解.该unsafe
方法unsafeRunAsync
似乎异步运行底层效果(我希望ContextShift
提供一些).但该方法看起来像这样:
final def unsafeRunAsync(cb: Either[Throwable, A] => Unit): Unit =
IORunLoop.start(this, cb)
Run Code Online (Sandbox Code Playgroud)
既没有ContextShift
也没有ExecutionContext
提供.这是一个非常简单的例子:
object TestIo extends App {
println(s"Main thread = ${Thread.currentThread().getName}")
val io = IO {
println(s"Effect thread = ${Thread.currentThread().getName}")
Thread.sleep(1000)
}
io.unsafeRunAsync(_ => println(s"Callback thread = ${Thread.currentThread().getName}"))
println(s"Finished")
}
Run Code Online (Sandbox Code Playgroud)
输出是
Main thread = main
Effect thread = main
Callback thread = main
Finished
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这里的所有内容都是在主线程中 同步运行的.你能解释一下unsafeRunAsync
吗?对我而言似乎是一样的unsafeRunSync
.
我有以下示例
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
typedef struct test{
int a;
long b;
int c;
} test;
int main()
{
test *t = (test*) malloc(offsetof(test, c));
t -> b = 100;
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我不确定.我想我在这里有UB.我们有一个指向结构类型对象的指针.但结构类型的对象并不真正有效.
我通过了标准,找不到这种行为的任何定义.我能找到的唯一一个接近这个的部分是6.5.3.2:
如果为指针分配了无效值,则unary*运算符的行为未定义
但这并不是真正相关的,因为返回的指针malloc
是完全有效的.
标准中是否有参考解释这种行为?我正在使用C11 N1570.
我正在阅读有关写入组合内存的英特尔优化手册并编写了基准测试以了解其工作原理。这些是我正在运行基准测试的 2 个函数:
memcopy.h
:
void avx_ntcopy_cache_line(void *dest, const void *src);
void avx_ntcopy_64_two_cache_lines(void *dest, const void *src);
Run Code Online (Sandbox Code Playgroud)
memcopy.S
:
avx_ntcopy_cache_line:
vmovdqa ymm0, [rdi]
vmovdqa ymm1, [rdi + 0x20]
vmovntdq [rsi], ymm0
vmovntdq [rsi + 0x20], ymm1
;intentionally no sfence after nt-store
ret
avx_ntcopy_64_two_cache_lines:
vmovdqa ymm0, [rdi]
vmovdqa ymm1, [rdi + 0x40]
vmovntdq [rsi], ymm0
vmovntdq [rsi + 0x40], ymm1
;intentionally no sfence after nt-store
ret
Run Code Online (Sandbox Code Playgroud)
这是基准测试的主要功能的样子:
#include <stdlib.h>
#include <inttypes.h>
#include <x86intrin.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include "memcopy.h" …
Run Code Online (Sandbox Code Playgroud) KbL i7-8550U
我正在研究 uops-cache 的行为并遇到了关于它的误解。
如英特尔优化手册2.5.2.2
(我的)中所述:
解码的 ICache 由 32 组组成。每组包含八种方式。 每路最多可容纳六个微操作。
——
Way 中的所有微操作表示在代码中静态连续的指令,并且它们的 EIP 位于相同的对齐 32 字节区域内。
——
最多三种方式可以专用于相同的 32 字节对齐块,从而允许在原始 IA 程序的每个 32 字节区域中缓存总共 18 个微操作。
——
无条件分支是 Way 中的最后一个微操作。
情况1:
考虑以下例程:
uop.h
void inhibit_uops_cache(size_t);
Run Code Online (Sandbox Code Playgroud)
uop.S
align 32
inhibit_uops_cache:
mov edx, esi
mov edx, esi
mov edx, esi
mov edx, esi
mov edx, esi
mov edx, esi
jmp decrement_jmp_tgt
decrement_jmp_tgt:
dec rdi
ja inhibit_uops_cache ;ja is intentional to avoid Macro-fusion
ret
Run Code Online (Sandbox Code Playgroud)
为了确保例程的代码实际上是 32 字节对齐的,这里是 asm …
java ×3
assembly ×2
c ×2
performance ×2
scala ×2
x86 ×2
avx ×1
c++ ×1
css ×1
hibernate ×1
html ×1
intel ×1
jvm-hotspot ×1
methods ×1
regex ×1
scala-cats ×1
spring-mvc ×1
struct ×1