我既有TCP服务器又有一个客户端,简单TCP服务器将仅接收传入的数据并进行打印,并且客户端将不断创建套接字连接并将数据循环发送到TCP服务器。
我得到的信息是,如果正确关闭了TCP连接,则此过程应继续进行而不会发生任何崩溃。
但是从客户端到服务器接收到一定数量的数据后,客户端崩溃并报错
total times data send: 16373
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10d7594]
goroutine 1 [running]:
main.sendData()
/Users/apple/Desktop/Personal/umbrellaserver/src/tests/clinet.go:178
+0xb4
main.main()
/Users/apple/Desktop/Personal/umbrellaserver/src/tests/clinet.go:170
+0x2a
exit status 2
Run Code Online (Sandbox Code Playgroud)
Server.go
package main
import (
"bufio"
"fmt"
"net"
"sync"
)
var wg sync.WaitGroup
var count = 0
var timeX string = ""
var connQueue = make(chan string)
func main() {
tcpListner := startTCPConnection()
incomingTCPListener(tcpListner)
}
//startTCPConnection
func startTCPConnection() net.Listener {
tcpListner, tcpConnectonError := …Run Code Online (Sandbox Code Playgroud) 我创建了一个Spring Restful Service和Spring MVC应用程序。
Restful Service :: Restful Service返回一个实体(如果它存在于数据库中)。如果不存在,则在ResponseEntity对象中返回自定义Exception信息。
它正在使用邮递员进行预期的测试。
@GetMapping(value = "/validate/{itemId}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity<MyItem> validateItem(@PathVariable Long itemId, @RequestHeader HttpHeaders httpHeaders) {
MyItem myItem = myitemService.validateMyItem(itemId);
ResponseEntity<MyItem> responseEntity = null;
if (myItem == null) {
throw new ItemNotFoundException("Item Not Found!!!!");
}
responseEntity = new ResponseEntity<MyItem>(myItem, headers, HttpStatus.OK);
return responseEntity;
}
Run Code Online (Sandbox Code Playgroud)
如果所请求的实体不存在,Restful Service将在下面返回。
@ExceptionHandler(ItemNotFoundException.class)
public ResponseEntity<ExceptionResponse> itemNotFEx(WebRequest webRequest, Exception exception) {
System.out.println("In CREEH::ItemNFE");
ExceptionResponse exceptionResponse = new ExceptionResponse("Item Not Found Ex!!!", new Date(), webRequest.getDescription(false));
ResponseEntity<ExceptionResponse> …Run Code Online (Sandbox Code Playgroud) 我有一个这样的 JPA 查询。
PersonRepository.java
public Optional<List<PersonEntity>> findByStatus(int status);
Run Code Online (Sandbox Code Playgroud)
人员服务.java
System.out.println(“Optional value is ”+findByStatus(1));
Run Code Online (Sandbox Code Playgroud)
输出是 Optional value is Optional.empty
现在我改变了我的查询 PersonRepository.java
public List<PersonEntity> findByStatus(int status);
Run Code Online (Sandbox Code Playgroud)
人员服务.java
Optional<List<PersonEntity>> optional = Optional.of(findByStatus(1));
System.out.println("Optional value is "+optional);
Run Code Online (Sandbox Code Playgroud)
输出是 Optional value is Optional[[]]
在我的数据库中,状态 1 没有值。我想要我的输出作为Optional[[]]第一个查询。我如何实现这一目标?
现在,我想实现这一点,因为每当optional.get()抛出 a 时NoSuchElementException,我将使用我的异常控制器处理它并将其作为 404 公开给 REST 层。但是,当List<Object>获取a 时,响应只是一个空 List,但optional.get()仍然抛出 a NoSuchElementException。我想避免这种情况。简而言之,NoSuchElementException如果没有找到值,那么从 Repository 中可选的 fetch 就会抛出,这是完美的。但是对于空实体列表的可选提取,应该返回为空而不是抛出,NoSuchElementException因为它不是 404 错误。这只是意味着该列表目前为空。
线程“主”中的异常java.lang.ClassCastException:无法将org.springframework.boot.devtools.restart.DefaultRestartInitializer上的java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader强制转换为java.base / java.net.URLClassLoader org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(DefaultRestartInitializer.java:56)上的.getUrls(DefaultRestartInitializer.java:93)org.springframework.boot.devtools.restart.Restarter。(Restarter.java:138)在org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:537)在org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartedEvent(RestartApplicationListener.java:68)在org.springframework.boot.devtools .restart.RestartApplicationListener。org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)上的org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)上的onApplicationEvent(RestartApplicationListener.java:45) org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:63)上的.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)在org.springframework.boot.SpringApplicationRunListeners.started(SpringApplicationRunListeners.java :48)在org.springframework.boot.SpringApplication.run(SpringApplication.java:304)在org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)位于com.rme.hub.RmeApplication.main(RmeApplication.java:24)
我正在学习SpringBoot。使用Spring JavaPersistenceAPI(JPA)和apache derby作为数据库。我在将URL映射到方法时遇到麻烦。
我有主题:
@Entity
public class Topic {
@Id
private String id;
private String name;
private String description;
public Topic() {
}
public Topic(String id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
} ... getters & setters...
Run Code Online (Sandbox Code Playgroud)
我有一个主题控制器。它工作正常:
@RestController
public class TopicController {
@Autowired
private TopicService topicServ;
@RequestMapping("/topics")
public List<Topic> getAllTopics() {
return topicServ.getAllTopics();
}
@RequestMapping("/topics/{topicId}")
public Topic getTopic(@PathVariable String topicId) {
return topicServ.getTopic(topicId);
}... more methods (they work fine) …Run Code Online (Sandbox Code Playgroud) 我遇到过多种算法,例如 Flajolet-Martin 算法、HyperLogLog 来从元素列表中找出唯一元素,突然好奇 Java 是如何计算的?在每种情况下存储和查找唯一值的时间复杂度是多少?
我在尝试更新实体列表(作业)时遇到错误:
Multiple representations of the same entity [com.introlabsystems.upworkscraper.model.entities.Skill#42] are being merged. Detached: [Skill(id=42, skillName=Web Scraping)]; Detached: [Skill(id=42, skillName=Web Scraping)]
Run Code Online (Sandbox Code Playgroud)
我认为这是三个实体与技能实体具有多对多关系的情况。
@Entity
public class Job {
@Id
@Column(unique = true, nullable = false)
@SerializedName(value = "ciphertext")
private String id;
@Column(length = 2048)
private String title;
@Column(columnDefinition = "TEXT")
@JsonAdapter(value = DescriptionAdapter.class)
private String description;
@SerializedName(value = "subcategory2")
private String category;
@ManyToMany(cascade = {
CascadeType.MERGE
}, fetch = FetchType.EAGER)
@JoinTable(
joinColumns = {@JoinColumn(name = "job_id")},
inverseJoinColumns = {@JoinColumn(name = "skill_id")}
)
@JsonAdapter(value …Run Code Online (Sandbox Code Playgroud) int main() {
long long int n, m, j, l, a[1000000000][1000000000];
int k, i;
scanf("%lld", & n);
scanf("%lld", & m);
for (j = 0; j < n; j++) {
for (l = 0; l < m; l++) {
a[j][l] = 0;
printf("%d\n", a[j][l]);
}
}
for (j = 0; j < n; j++) {
for (l = 0; l < m; l++) {
printf("%d\n", a[j][l]);
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我总是遇到运行时错误。有人可以建议我解决它吗???我需要这个来解决一个竞争性编程问题,其中棋盘可能有 1000000000*1000000000 个方格,我需要用它执行多项操作。
java ×5
spring-boot ×4
spring ×2
arrays ×1
big-o ×1
c ×1
flutter ×1
go ×1
hibernate ×1
hyperloglog ×1
jpa ×1
long-integer ×1
optional ×1
padding ×1
set ×1
spring-mvc ×1
spring-rest ×1
stack ×1
tcp ×1
tcpclient ×1
tcplistener ×1
text ×1
widget ×1