我有一个 docker-compose 文件和一个 Dockerfile。MySQL 已正确安装。我已经设置了MYSQL_ROOT_PASSWORD。但是当尝试访问 mysql db 时,出现错误 - 访问被拒绝。我已阅读本网站的其他主题,但无法获得太多帮助。:(
这是我的 docker-compose 文件:
version: '3'
volumes:
db_data: {}
services:
db:
build:
context: .
dockerfile: ./db/Dockerfile
args:
- database=iTel
- password=123
image: db_image
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
Run Code Online (Sandbox Code Playgroud)
和 Dockerfile:
FROM mysql:5.7.15
ARG database
ARG password
RUN echo ${database}
RUN echo ${password}
MAINTAINER me
ENV MYSQL_DATABASE=${database} \
MYSQL_ROOT_PASSWORD=${password}
ADD ./db/database100.sql /docker-entrypoint-initdb.d
EXPOSE 3306
Run Code Online (Sandbox Code Playgroud)
以下是构建日志:
docker-compose up -d
Building db
Step 1/9 : FROM mysql:5.7.15
5.7.15: Pulling from library/mysql …
Run Code Online (Sandbox Code Playgroud) 我不熟悉这个用java发送邮件的功能.发送电子邮件重置密码时收到错误.希望你能给我一个解决方案.
以下是我的代码:
public synchronized static boolean sendMailAdvance(String emailTo, String subject, String body)
{
String host = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-ADDRESS");
String userName = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-USERNAME");
String password = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-PASSWORD");
String port = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-PORT");
String starttls = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-STARTTLS");
String socketFactoryClass = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-SOCKET-CLASS");
String fallback = AppConfigManager.getProperty("SENDER-EMAIL-SMTP-ALLOW-FALLBACK");
try
{
java.util.Properties props = null;
props = System.getProperties();
props.put("mail.smtp.user", userName);
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
if(!"".equals(port))
{
props.put("mail.smtp.port", port);
props.put("mail.smtp.socketFactory.port", port);
}
if(!"".equals(starttls))
props.put("mail.smtp.starttls.enable",starttls);
if(!"".equals(socketFactoryClass))
props.put("mail.smtp.socketFactory.class",socketFactoryClass);
if(!"".equals(fallback))
props.put("mail.smtp.socketFactory.fallback", fallback);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
MimeMessage msg …
Run Code Online (Sandbox Code Playgroud) 我将一个接口作为匿名实现传递给另一个对象,如下所示:
public interface Interface {
public int convert (int a);
}
public static void main(String[] args) throws IOException, InterruptedException {
final int[] array = {1,6,3,5,7,8,4,0,3};
Interface inter = new Interface() {
public int convert(int a) {
int result = a;
for (int i = 0; i < array.length; i++) {
a=a+array[i];
}
return a;
}
};
SomeObject ty = new SomeObject ();
ty.Test(7, inter);
}
public class SomeObject {
public void Test(int number, Interface inter) {
System.out.println(inter.convert(number));
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:它是如何工作的?如何 …
我是OOP的新手。最近,我读到了《里斯科夫替代原理》。
在下面给出的代码中,Square类继承了Give_Area。假设Square类与平方有关(例如有效性检查)。Give_Area给出正方形的面积(4个顶点在一个圆的周长上)和一个圆的面积。因此,如果给我一个Radius,我必须打印圆和正方形的区域(由放置在该圆的周长上的顶点组成)。为了得到一个圆的面积,我使用了一个参数。但是获取平方面积时没有参数。因此,我在这里做了重载。
#include<iostream>
#include<cmath>
using namespace std;
class Give_Area
{
public:
double Radius;
double Area(double pi)
{
return pi*Radius*Radius;
}
double Area()
{
double temp = sqrt(2.0)*Radius;
return temp*temp;
}
};
class Square : public Give_Area
{
public:
bool Validity()
{
//checking validity
}
};
int main()
{
Give_Area* area = new Square();
area->Radius = 3.0;
cout<< "Area of Circle: " << area->Area(3.14159) <<endl;
cout<< "Area of Square: " << …
Run Code Online (Sandbox Code Playgroud) 我一直在阅读Head First for multithreading.我对多线程的了解是:
当我们用Thread类的对象调用start()时,线程进入Runnable状态.因此,在通过这些线程的对象调用start()之后,所有线程都进入Runnable状态.它是JVM线程调度程序,它从Runnable状态中随机选择线程以使其处于Running状态.进入运行状态后,将执行该特定线程的确定调用堆栈.
同样,JVM线程调度程序可以通过从运行状态选择该线程到Runnable状态来停止执行线程.这次,代码执行暂停在该线程的调用堆栈中.
现在我的问题是,对于多处理器机器,JVM线程调度程序如何从Runnable状态中选择线程?它只选择一个线程并将其提供给处理器吗?或者,它是否选择多个线程并将这些线程分配给不同处理器的运行状态?
我写了下面的代码:
// Class of main thread
public class ThreadMain {
public static void main(String[] args) {
Runnable threadJob=new MyRunnable();
Thread t=new Thread(threadJob);
t.start();
System.out.println("Back in the Main");
}
}
// Class of another thread
public class MyRunnable implements Runnable{
public void run()
{
System.out.println("I'm Thread");
}
}
Run Code Online (Sandbox Code Playgroud)
这里有两个主题.主线程和我创建的线程.如果我的机器有多处理器,它会如何表现?JVM线程调度程序是否会一次选择两个线程,并将它们分配给两个多处理器?
今天当我使用流平均值编写代码时,我知道流平均返回OptionalDouble
而不是double
.我知道为什么OptionalDouble
用于.
当我们调用流平均值以便我们需要OptionalDouble时,还可以返回什么?
一个例子将非常感激.提前致谢.
我的代码如下:
OptionalDouble average = persons.stream()
.mapToInt(person -> person.getAge())
.average();
if(average.isPresent()) {
System.out.println(average.getAsDouble());
}
Run Code Online (Sandbox Code Playgroud)
这里persons
是一个ArrayList
的Person
类.
我正在练习流。然后得到了这种奇怪的行为。我想不通原因。这就是为什么寻求帮助。
我是这样写的:
IntStream.iterate(10, i -> i - 2)
.limit(5)
.sorted()
.takeWhile(i -> i > 2)
.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
这在控制台中没有给我任何信息,这是预期的。当我在 IntelliJ IDEA 中看到流链时,得到:
因此,在执行sorted()后,它只向管道返回一个元素(该元素在图像中为 2)。
现在我评论了takeWhile()调用。像这样:
IntStream.iterate(10, i -> i - 2)
.limit(5)
.sorted()
// .takeWhile(i -> i > 2)
.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
这也按预期在控制台中打印(从 10 到 2,相差 2)。
但问题是,这次sorted()向管道返回了 5 个元素。当我在 IntelliJ IDEA 中看到流链时,得到:
我的问题是,为什么在调用sorted() 时会看到差异?如果sorted()之后有takeWhile( )则它返回一个元素。如果我评论takeWhile(),sorted()将返回 5 个元素的流。
JVM 是否在这里做任何事情来获得更好的性能?
提前致谢.....
当我写这段代码时:
#include <stdio.h>
int main()
{
printf("%p\n",main);
printf("%d\n",main);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的编译器向我展示了这个输出:
00401318
4199192
Run Code Online (Sandbox Code Playgroud)
我很想知道实际打印了什么。我用谷歌搜索了我的问题,但一无所获。:(
提前致谢。
double b_sort(sample &s){
int swap;
int i = 0;
int size = s.get_data().size();
vector <double> vec;
for (i; i < size; i++){
if (s.get_data().at(i) < s.get_data().at(i + 1){
swap = s.get_data().at(i + 1);
s.get_data().at(i + 1) = s.get_data().at(i);
s.get_data().at(i) = swap;
}
}
return //dont know what to return;
}
Run Code Online (Sandbox Code Playgroud)
我正在排序由用户使用bubblesort定义的向量.但是我不知道如何返回排序的矢量.
任何帮助将不胜感激.
我正在尝试用java读取文件.在该文件中,给出了一些我要打印的字符串.但我的代码只打印偶数行和跳过奇数行.
我在stackoverflow中搜索了它,但是之前没有找到解决方案.
我的代码如下:
//main class
import java.io.IOException;
public class takingInputFrpmFile {
public static void main(String[] args) throws IOException {
String filePath = "F:/Path/in.txt";
try
{
readFile rF = new readFile(filePath);
String[] receivedArray = rF.Read();
for(int i=0;i<receivedArray.length;i++)
System.out.println(receivedArray[i]);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
// class called from main class
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class readFile {
private String path;
public readFile(String path)
{
this.path=path;
}
public String[] Read() throws IOException
{
FileReader fR …
Run Code Online (Sandbox Code Playgroud) java ×6
c++ ×2
java-stream ×2
jvm ×2
bubble-sort ×1
c ×1
docker ×1
dockerfile ×1
file ×1
function ×1
jakarta-mail ×1
liskov-substitution-principle ×1
mysql ×1
optional ×1
return ×1
sorting ×1
vector ×1